Thursday, April 22, 2021

IONIC PASS PARAMETER

 To pass parameter to next page, first we need to make sure that we have 2 pages which is page from and page to. In page from ts file, you have to import router at the top of the file as below.

import { RouterNavigationExtras } from '@angular/router';

Make sure to load in constructor also.

constructor(private router: Router) {
    
}

Then create one function to navigate to another page with parameter.

somefunction(menu) {

    // this.message = name;

    let navigationExtras: NavigationExtras = {
      queryParams: {
        title: this.message,
        data: JSON.stringify(menu)
      }
    };

    this.router.navigate([menu.link], navigationExtras);
    // alert(this.message);

}

Those function will be called in html file and the menu is based on data that will be passed. Below I provide full code in page from ts file.

import { Component } from '@angular/core';
import { RouterNavigationExtras } from '@angular/router';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {

  message = 'Testing';

  menus = [
    {
      name: 'menu 1',
      desc: 'desc 1',
      color: 'primary',
      link: '/dummy',
      image: '',
    },
    {
      name: 'storage',
      desc: 'desc 2',
      color: 'success',
      link: '/storage',
      image: '',
    },
    {
      name: 'Users',
      desc: 'desc 3',
      color: 'tertiary',
      link: '/users',
      image: '',
    },
    {
      name: 'menu 3',
      desc: 'desc 3',
      color: 'warning',
      link: '/dummy',
      image: '',
    },
  ];

  constructor(private router: Router) {
    // this.somefunction();
  }

  somefunction(menu) {

    // this.message = name;

    let navigationExtras: NavigationExtras = {
      queryParams: {
        title: this.message,
        data: JSON.stringify(menu)
      }
    };

    this.router.navigate([menu.link], navigationExtras);
    // alert(this.message);

  }
}



Then we will proceed with 2nd page which is page to. In this page ts file, we will get the parameter that have been submit to this page. First, you also have to import router at the top of the file as below.

import { ActivatedRouteRouter } from '@angular/router';

Make sure to load in constructor also and get the parameter inside the constructor as below.

constructor(
    private route: ActivatedRoute
    private router: Router,
    private helper: HelperService,
  ) {

    this.route.queryParams.subscribe(params => {
      if (params && params.title && params.data) {
        this.title = params.title
        this.data = JSON.parse(params.data);
      }
    });

   }

below is the full code for second page.

import { ComponentOnInit } from '@angular/core';
import { ActivatedRouteRouter } from '@angular/router';
import { HelperService } from '../services/helper.service';

@Component({
  selector: 'app-dummy',
  templateUrl: './dummy.page.html',
  styleUrls: ['./dummy.page.scss'],
})
export class DummyPage implements OnInit {

  title;
  data;
  loading;

  constructor(
    private route: ActivatedRoute
    private router: Router,
    private helper: HelperService,
  ) {

    this.route.queryParams.subscribe(params => {
      if (params && params.title && params.data) {
        this.title = params.title
        this.data = JSON.parse(params.data);
      }
    });

   }

  ngOnInit() {
    // this.presentToast('Trasyy uihdwiue jk', 500);
    // this.presentLoading();
    this.helper.presentLoading();

    setTimeout(() => {
      this.helper.dismissLoading();
      this.helper.presentAlert();
    }, 2000);
  }

}

Thursday, March 25, 2021

IONIC BASIC SETUP

 Before you start to install ionic, make sure you computer have node js and npm. Click here to download node js.

After that open your cmd and download ionic using npm. Make sure to open directory where you install the nodejs that contain npm.


$ npm install -g @ionic/cli



After you have install ionic, open a directory where you want to keep your project in cmd. Then run the script below. This script need to run everytime you want to create a new project.


ionic start

- select js framework. exp : angular

- name your project. exp : myapp

- select template. exp : blank


You have done created your project !!! Then open your project directory to open serve to preview project.


ionic serve

- after serve is running, you can view in browser or you can open in vs code.

- ctrl + shift + p > search ionic preview (in vscode)



To add new page for your app, open project directory and run :


ionic g page 'page name'  remove ''

or

ionic g




cmd script summary ...


npm install -g @ionic/cli

ionic start

ionic serve

ionic g page 'page name'  remove ''

ionic g


Monday, November 2, 2020

SERVER FORCE HTTP to HTTPS

 Add this script inside .htaccess file to force https.


RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Monday, July 20, 2020

CODEIGNITER IMAGE AUTO ROTATE WHEN UPLOAD USING MOBILE

I have a project that can upload image. During I upload an image using desktop, the image if fine. But if I upload an image using my phone, the image will rotated automatically.

Solution

1) You need to add a new library.The library automatically rotates the provided image based on the embedded EXIF data. I use it in my projects to correctly display images uploaded from mobile devices

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* @file application/libraries/Image_autorotate.php
*/
class Image_autorotate
{
    function __construct($params = NULL) {
    
        if (!is_array($params) || empty($params)) return FALSE;
        
        $filepath = $params['filepath'];
        $exif = @exif_read_data($filepath);
        
        if (empty($exif['Orientation'])) return FALSE;
        
        $CI =& get_instance();
        $CI->load->library('image_lib');
        
        $config['image_library'= 'gd2';
        $config['source_image'= $filepath;
        
        $oris = array();
        
        switch($exif['Orientation'])
        {
        case 1// no need to perform any changes
        break;

        case 2// horizontal flip
        $oris[] = 'hor';
        break;
                                        
        case 3// 180 rotate left
        $oris[] = '180';
        break;
                            
        case 4// vertical flip
        $oris[] = 'ver';
        break;
                        
        case 5// vertical flip + 90 rotate right
        $oris[] = 'ver';
        $oris[] = '270';
        break;
                        
        case 6// 90 rotate right
        $oris[] = '270';
        break;
                        
        case 7// horizontal flip + 90 rotate right
        $oris[] = 'hor';
        $oris[] = '270';
        break;
                        
        case 8// 90 rotate left
        $oris[] = '90';
        break;
        
        defaultbreak;
        }
        
        foreach ($oris as $ori) {
        $config['rotation_angle'= $ori;
        $CI->image_lib->initialize($config);
        $CI->image_lib->rotate();
        }
    }
}
// END class Image_autorotate
/* End of file Image_autorotate.php */
/* Location: ./application/libraries/Image_autorotate.php */
Place this file inside library folder.

2)  call this library after you have upload an image.

$imageinfo = $this->upload->data();
$full_path = $imageinfo['full_path'];

// check EXIF and autorotate if needed
$this->load->library('image_autorotate', array('filepath' => $full_path));


Reference :-

Saturday, April 25, 2020

CodeIgniter PHP : Merge Array

There are condition when we have two array and want to combine them. In PHP, we can use function array_merge() to merge those to array.
Below is the example how to use the function.


<?php
    $a1=array("a"=>"red","b"=>"green");
    $a2=array("c"=>"blue","b"=>"yellow");
    print_r(array_merge($a1,$a2));
?>

Result :
Array ([a]=>red [b]=>yellow [c]=>blue)

As you can see there are two value for key=b. But the result is going to print the 2nd array array as the value.

Tuesday, October 15, 2019

MySQL Insert or Update column with value from another table

INSERT

Sometimes, there was an old data that need to be transfer from old table to new table. However, not all fields are required to transfer. So, below is the example of two tables and fields, and the sql statement.
tableOld
id     name     ic_no     phone_no     address
tableNew
id     name     ic_no     phone_no     

MySQL statement

INSERT INTO tableNew (name,ic_no,phone_no)
  SELECT name,ic_no,phone_no FROM tableOld 
  WHERE tableOld.id > 1;
This SQL statement is called as insert into select.


UPDATE

In this case, I want to get value from table1 to update into table2 based on certain condition or value.
For example :-
table1
id     name     ic_no     phone_no
table2
id     name     phone_no     address
I want to get phone_no from table1 and update the value phone_no into table2 with condition table2.name = table1.name.

MySQL statement
UPDATE table2 t2 
        INNER JOIN table1 t1 
             ON t2.name = t1.name
SET t2.ic_no= t1.ic_no
WHERE t2.name = t1.name;

Tuesday, February 26, 2019

Codeigniter How to make Onclick showHide Radio Button Function (Javascript)


All the code will be coded inside view file. First make your radio button.

<input type="radio" id="expense" name="transaction" onclick="ShowHideDiv()" checked /><?php echo lang('title_expense')?>
<input type="radio" id="income" name="transaction" onclick="ShowHideDiv()" /><?php echo lang('title_income')?>

Make sure the radio button have an id and the same name. Also put onclick that equal to function that you want. For this project we want ShowHideDiv  func.

Then make the div that you want to show or hide.

<div id="expense_list" style="block: none">
//anything that you want to put inside this div
//it can be table or something
</div >

<div id="income_list" style="show: none">
//anything that you want to put inside this div
//it can be table or something
</div >


Lastly make the jquery script to make the ShowHideDiv() func.

<script type="text/javascript">
function ShowHideDiv() {
    var expense = document.getElementById("expense");
    var income = document.getElementById("income");
    var expense_list = document.getElementById("expense_list");
    var income_list = document.getElementById("income_list");
    expense_list.style.display = expense.checked ? "block" : "none";
    income_list.style.display = income.checked ? "block" : "none";
}
</script>


"block" : "none"  - means the func to hide the content is block.
"show" : "none"  - means the func will show nothing.(hide content)

Monday, February 25, 2019

CodeIgniter How to Make send Email Function

First, make a hidden form of table id in view to call it at controller.

View

echo form_hidden('id', $table->id);


Then make a send_email function inside controller file.

Controller

  public function send_email($id)
  {
    $leave = $this->one_model->get('table', $id);
    $staff = $this->one_model->get('staff', $leave->created_by);
    $approver = $this->one_model->get('staff', $staff->leave_approver_id);
    $organization = $this->one_model->get('organizations', $leave->org_id);
    $apply_date = date_create($leave->created_at);
    $apply_date = date_format($apply_date, DATE_FORMAT);
    $date_start = date_create($leave->date_start);
    $date_start = date_format($date_start, DATE_FORMAT);
    $date_end = date_create($leave->date_end);
    $date_end = date_format($date_end, DATE_FORMAT);

    // construct msg - with invoice link inside
    $message = '

Permohonan cuti diterima seperti berikut:

Pemohon Cuti: '.$staff->name.'
Tarikh Permohonan: '.$apply_date.'
Tarikh Mula: '.$date_start.'
Tarikh Akhir: '.$date_end.'
Jumlah Hari: '.$leave->total_day.'
Sebab: '.$leave->reason.'

Untuk memberi maklum balas sila ke localhost/smap/lu/'.$leave->secure_id.'

Terima kasih';


    $this->load->library('mailgun');

    $this->mailgun->from("$organization->name<postmaster@mg.smap.my>");
    $this->mailgun->reply_to($organization->email);
    $this->mailgun->to($approver->email);
    $this->mailgun->bcc('hello@smap.my');

    $this->mailgun->subject("Permohonan Cuti ($staff->name)");
    $this->mailgun->message($message);

    $this->mailgun->send();

  }


Controller process

    $id = $post['id'];

    $this->send_email($id);



CodeIgniter How to make filter function

How to make filter function in PHP.

View

For view, first make the dropdown list and filter button.

<?php echo form_open(''); ?>
<table width="100%">
<tr>
<td align="right">
<?php echo form_dropdown('name', $array_list, $selected_array, 'class="form-control input-inline input-small"'); ?>
<input type="submit" value="<?php echo lang('lbl_filter'); ?>" class="btn btn-primary" />
</td>
</tr>
</table>
<?php echo form_close(); ?>


'name' = data name that will to represent the data and be used to call in controller.
$array_list = data that you want to display inside the dropdown.
$selected_array = array that you have select to filter.



Controller list

$data = array();

      $data['selected_array'] = '';
  
      if ($post = $this->input->post()) {
        $post = $post = $this->input->post();
        $data_name = $post['name']; //data name that hv been set in view
  
        if (!empty($name)) {
          $this->db->where("column in table = $data_name");
          $data['selected_array'] = $data_name;
        }
      }

This controller is used to set the filter function.

@getnada

@getnada

What is @getnada ?

An temporary email services to avoid spam. It is mean that we get a chances to create a temporary email address and remain active long enough for you to receive a reply from whoever the address was given to. Then you don't have to use it again.


How to use nada?

1. Go to @getnada.com
2. Click Add Inbox - put any names you want and choose any domain
3. Then paste the email created at any places you want
4. Inbox will received according your email created


Thursday, January 31, 2019

80-20 Rule

80-20 RULE EXPLAINED

The 80 20 rule, also known as Pareto Principle is one of the helpful concepts for life and management. This rule suggests that 20 percent of your activities will account for 80 percent of your result.

20% activities ===> 80% results.

How Does It Work ?

The concept suggests two out of ten items, on any general to-do list, will turn out to be worth more than the other eight items put together.

The sad fact is that most people do not focusing on the 20% of things that are most valuable and important but more focused on the 80% of that are least important.

How To Apply ?

1. First list down some thing that you want to do.

2. Then sort them according to the most important to the least important.

3. Lastly, start to do your work based on the most important task first. 

Wednesday, January 30, 2019

PERSONALITI PLUS (MALAY)

PERSONALITI +

Di dalam kehidupan, terdapat empat jenis personaliti berbeza yang ada pada manusia. Setiap orang akan memiliki satu personaliti. Antara empat personaliti itu ialah api, tanah air dan juga angin. Keempat-empat personaliti berikut mempunyai cir-ciri yang tersendiri.

API

Elemen api lebih kepada mereka yang berani untuk mengambil risiko. Antara sifat-sifat yang ada pada elemen api adalah :-
  • kreatif
  • dinamis
  • aktif
  • inovatif
  • suka bersuara
  • suka mengambil risiko

Kelebihan :

Antara kelebihan elemen api adalah mereka cepat mengadaptasikan diri apabila mereka masuk ke tempat baru. Mereka sering mendapat perhatian, dan jika perlu, mereka akan bersaing untuk menunjukkan siapa yang terbaik. Sifat mereka yang berani mengambil risiko membuatkan orang yang lain kagum.

Kelemahan :

Kebanyakan mereka yang mempunyai elemen api hanya suka mencari kawan atau teman yang boleh membuat mereka untung. Emosi api yang membara ternyata hanya untuk mendapatkan perhatian dan menunjukkan siapa yang terbaik. Mereka juga suka menyakitkan perasaan orang lain demi mendapatkan apa yang mereka mahu.

//Elemen yang sesuai untuk elemen api ialah air kerana mereka boleh menenangkan api saat api tidak dapat dikawal.


Air

Elemen air lebih kepada mereka yang suka berimaginasi. Antara sifat-sifat yang ada pada elemen air adalah :-
  • emosional
  • sensitif
  • penyayang
  • mudah tersentuh
  • bernaluri tajam
  • mempunyai daya imaginasi yang tinggi
  • kreatif

Kelebihan :


Antara kelebihan elemen air ialah mereka sentiasa terlihat tenang dan berkeyakinan diri. Mereka terkenal dengan pergaulan mereka yang tenang yang boleh membuatkan orang sekeliling berasa selesa di samping mereka. Salah satu sifat menonjol mereka ialah mereka tidak ragu-ragu untuk membantu orang yang susah kerana sifat mereka yang mudah tersentuh dan sensitif itu. Walaupun nampak santai, elemen air memiliki potensi luar biasa untuk mencapai matlamat. Tidak mengejutkan sekiranya mereka berjaya dalam bidang karier mahupun percintaan. Kuncinya hanya kombinasi kecerdasan otak dan mengambil peluang di depan mata.

Kelemahan :

Elemen ini suka bergurau namun tidak suka apabila diri mereka dijadikan bahan ketawa. Mereka suka berdendam dan akan membalasnya yang kadang-kadang kita tidak sedar. Sekiranya mereka tidak dihargai, mereka sanggup untuk membuat orang lain berasa tidak tenang. 

//Elemen yang sesuai untuk elemen air ialah api kerana boleh menyeimbangkan keduanya walaupun berbeza pendapat.

Tanah

Elemen tanah lebih kepada mereka yang suka bekerja keras. Antara sifat-sifat yang ada pada elemen tanah adalah :-
  • merendah diri
  • well organized
  • bermatlamat
  • bekerja keras
  • boleh dibawa berbincang
  • penuh dedikasi

Kelebihan :


Antara kelebihan elemen tanah ialah mereka tidak membuang masa. Mereka juga lebih suka berada di belakang daripada menonjol di depan umum sesuai dengan sifat mereka yang merendah diri dan pemalu. Elemen tanah tidak perlu susah-susah untuk mencari kawan kerana orang sekeliling suka akan sifat keperibadian mereka. Sebagai rakan tempat kerja, elemen tanah memang mudah dibawa bincang untuk menghadapai saat sukar bersama-sama. Sanggup mengorbankan kesenangan peribadi, untuk memberikan yang terbaik kepada orang sekeliling mereka. Kebanyakan tanah mampu mencapai puncak karier. Beruntungnya, kejayaan mereka itu selalu mendapat sokongan penuh oleh semua orang.

Kelemahan :

Walaupun terlihat seperti tidak suka dipuji, sebenarnya mereka sangat menikmatinya. Bagi mereka, pujian merupakan semangat untuk mereka meningkatkan kepercayaan diri. Tanah juga bisa menjadi pengkhianat terselubung jika mendapat kepercayaan berlebihan dengan alasan ingin menunjukkan teori mereka betul. Perhatian tanah yang terperinci boleh membuatkan orang sekeliling tidak senang. Jika tidak bisa mengikuti kerja mereka, mereka lebih memilih untuk bekerja sendiri.


//Elemen yang sesuai untuk elemen tanah ialah angin kerana angin fleksibel untuk melayan karenah tanah.


Angin

Elemen angin lebih kepada mereka yang mudah untuk beradaptasi. Antara sifat-sifat yang ada pada elemen angin adalah :-
  • energik
  • multitasking
  • mudah bergaul
  • elegen
  • pandai berkomunikasi
  • semangat berpasukan

Kelebihan :



Kelemahan :




//Elemen yang sesuai untuk elemen tanah ialah angin kerana angin fleksibel untuk melayan karenah tanah.

Sunday, January 27, 2019

HOW TO USE GITLAB

How To Use Gitlab ?



Gitlab Process

When converting to git you have to get used to the fact that there are three steps before a commit is shared with colleagues. Most version control systems have only one step, committing from the working copy to a shared server

Three steps :-

1. Add file from the working copy to the stage area.

2. The file then will be transfer into the local repo.(repository)

3. Lastly, pushed the file to a shared remote repository.



All of the steps have been explained above. To be more specific :-

1. Start from using Sourcetree, click on the master branch and make a new branch.

2. Any changes on file that you want to make must be at that branch. Make sure to not making any change at master branch.

3. After you have finished make a change, at the new branch click on the file status. Then stage all the file that you have make a change. Then click commit to commit all the file.

4. After that, click push to push all the files to a shared remote repository.

5. Then open your Gitlab, and make a request to merge your branch with the master branch. (merge request)

6. Just wait until your request being approved.

7. If approved, click pushed to pushed the new merge file.

Wednesday, January 23, 2019

GIT

What is GIT ?

Definition 

Open source distributed version control system designed to tracking changes in source code during project development.

Git have a lot of software tools that can be used. The most familiar tools are Github and Gitlab.
For me, i have used Gitlab during my internship.








Function of Git

Git is version control system or can be called as source control, is the management of changes to documents, computer programs, large web sites, and other collections of information. This system is used when a project is done in a group or company. Any changes that have been done by one developer can be seen by others developer, so that the project is standardized. 


Type of Workflow

There are several type of workflow for Git. What is Git workflow ?
Git workflow is a recommendation for how to use Git to accomplish work in a consistent and productive manner.

Centralized Workflow

........

Feature Branch Workflow

........

Gitflow Workflow

...........

Forking Workflow

............

IONIC PASS PARAMETER

 To pass parameter to next page, first we need to make sure that we have 2 pages which is page from and page to. In page from ts file, you h...