Yii2+Pusher, Push Notifications

Juli 27, 2016

Langsung aja nih, kali ini saya coba bikin Notification di Web menggunakan Yii dan pusher, apa itu pusher, baca aja sendiri 😀 https://pusher.com/ , untuk menggunakan pusher ini anda harus mendaftar terlebih dahulu kemudian anda akan mendapatkan id,key, secret, yang nantinya digunakan sebagai token ke pusher,(lihat contoh di situsnya)  naa untuk menambahkan ke yii kita menggunakan composer installnya ambil di github di sini https://github.com/pusher/pusher-http-php , naa baru lanjut ke yii, saya gunakan yii advanced,

 

  • backend – PushController.php

use Pusher;

...

...

...

public function actionPush()
{

$model = new DynamicModel(['msg']);
$model->addRule(['msg'], 'string', ['max' => 128]);

if ($model->load(Yii::$app->request->post())){
$msg=$model->msg;
$app_id = 'YOUR_APP_ID';
$app_key = 'YOUR_APP_KEY';
$app_secret = 'YOUR_APP_SECRET';

$pusher = new Pusher( $app_key, $app_secret, $app_id );
$pusher->trigger('test_channel', 'my_event', ['message' => $msg] );
return $this->redirect(['push','model'=>$model]);

}else{

return $this->render('push',[
'model'=>$model,
]);
}
}

  • View/Push.php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;

$this->title = 'Notifikasi';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-login">
<h1><?= Html::encode($this->title) ?></h1>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'push-form']); ?>

<?= $form->field($model, 'msg')->label('Pesan')->textInput(['autofocus' => true]) ?>

<div class="form-group">
<?= Html::submitButton('Push', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
</div>

<?php ActiveForm::end(); ?>
</div>
</div>
</div>

selanjutnya untuk di frontend

  • view – main.php

<script src="https://js.pusher.com/3.1/pusher.min.js"></script>
<script>

// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;

var pusher = new Pusher('ce901ef053e354fcd965', {
encrypted: true
});

var channel = pusher.subscribe('test_channel');
channel.bind('my_event', function(data) {
// alert(data.message);
var message = data.message;
toastr.info(message);
});
</script>

  • appasset.php

public $css = [
'css/site.css',
"//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css"
];
public $js = [
'//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js'
];

naa udah gitu aja master, kemudian jalankan bagian backend (atas) jalankan frontend (bawah) di window tab baru,

1

kemudian isi dan tekan push

2

hasilnya begitu lah master 😀 , moga mengerti dan paham, sama sama belajar kita 😀


Mengirim Email via Foxpro

Juni 20, 2016

biar keren judulnya hehe, ok langung aja yaa kita akan kirim email dapat referen dari sini http://www.w3schools.com/asp/asp_send_email.asp

 

koding foxpronya


LOCAL myMail as "CDO.Message"
myMail = CreateObject("CDO.Message")
myMail.Subject = "Link 'tausyiah' "
myMail.From = "atmanegara1989@gmail.com"
myMail.To = "atma_1989@yahoo.com"
myMail.TextBody = "Bro ini file kumpulan video 'tausyiah' "
myMail.AddAttachment("D:\fileku.txt")

myMail.Configuration.Fields.Item;
("http://schemas.microsoft.com/cdo/configuration/sendusername") = 'atmanegara1989@gmail.com'
myMail.Configuration.Fields.Item;
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = '***********'
myMail.Configuration.Fields.Item ;
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

myMail.Configuration.Fields.Item ;
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

myMail.Configuration.Fields.Item;
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465

myMail.Configuration.Fields.Item;
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
myMail.Configuration.Fields.Item;
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = .t.
myMail.Configuration.Fields.Update
lcError=0
TRY
myMail.Send
CATCH TO err
lcError=err.ErrorNo
IF lcError=1429
MESSAGEBOX("Username & Password tidak sesuai atau Koneksi Internet Bermasalah..!!",0+16,"Kesalahan")
ELSE
MESSAGEBOX("Telah terjadi kesalahan..!!",0+16,"Kesalahan")
ENDIF
FINALLY
IF lcError=0
MESSAGEBOX("Email Success...!!",64,"Informasi",30)
ELSE
MESSAGEBOX("Email Unsuccess...!!",64,"Informasi",30)
ENDIF
ENDTRY

terus jalankan kan, jika terkirim

dan hasilnya

emailpng

sukses juga yaa

[edit]

btw ketinggalan, krn pake gmail, maka diperlukan akses ke gmail dari aplikasi yang teknologinya kurang aman kata google ,settingnya dari gmail,
sini linknya, pastikan login dulu biar email kita tersetting

https://support.google.com/accounts/answer/6010255

emailpng

untuk cari ip/server smtp dan portnya bisa cek disini

https://www.arclab.com/en/kb/email/list-of-smtp-and-pop3-servers-mailserver-list.html


Menggunakan Frx2any di Report Foxpro

Juni 1, 2016

Lagi iseng aja sih sebenarnya cuma penasaran, initnya ni frx2any sama kaya xfrx atau foxypreviewer , sama sama ada fasilitas export baik ke pdf,word,html, or excel, naa perbedaan antara xfrx,foxypreviewer dengan frx2any adalah di fasilitas export frx ke excel, xfrx or foxypreview hasilnya berantakan apalagi border border/garis garis nya mencar kemana mana ada yang ke mergen cell, juga tp klo dengan frx2any aku anggap rapi tampilannya, contoh

Capture

naa klo mau coba bisa langsung http://www.frx2any.com/ yang pasti ini beli lah, mau gratisan yaa pake foxyprewievew aja atau pake template excel (rekomen banget klo ini ) atau PM ane aja 🙂


Memanfaatkan Libary VFP2C32 (VFP to C 32 bit)

Mei 24, 2016

sayang klo ga dimanfaatkan 😀 libary yang cukup lengkap bisa dimanfaatkan silakhan di gunakan dan pastikan juga instal intellisense dan baca help nya 🙂 , liat aja deh examplenya bisa download disini http://vfpx.codeplex.com/wikipage?title=VFP2C32&referringTitle=Home


Custom Papersize Report Foxpro (II)

Mei 22, 2016

Bagian 2 hehe, langsung aja yaa, jadi ceritanya ada client yang mempunya standar ukuran kertas na klo 1 client ga apa apa bisa didatangin bagaimana klo banyak client, dengan standar berbeda repot dah engkau :D, alternatif kita bikin custom secara programing reportnya dengan foxpro, langsung aja nih

pertama bikin report(pastinya), selanjtunya bikin program (.prg) dengan nama newpaper.prg, selanjutnya bikin procedure dengan nama customPaper dan Idpaper


Procedure customPaper(lcNamaPaper)
Local hPrinter
Local cPrinterName, cPaperName
Local pPaperName, sPaperSize
Local nResult, nBufLen, nPaperWidth, nPaperHeight

Declare Long GetLastError In Kernel32
Declare Long ClosePrinter In WinSpool.Drv Long hPrinter
Declare Long OpenPrinter In WinSpool.Drv ;
String cPrinterName, Long @O_hPrinter, Long pDefault

Declare Long GetForm In WinSpool.drv As GetPrinterForm ;
Long hPrinter, String pFormName, ;
Long nLevelInfo, String @O_pFormInfo, ;
Long nBufSize, Long @O_nBufNeeded

Declare Long AddForm In WinSpool.drv As AddPrinterForm ;
Long hPrinter, Long nLevelInfo, String @pFormInfo

Declare Long LocalAlloc In Kernel32 Long uFlags, Long dwBytes
Declare Long LocalFree In Kernel32 Long Hmem

cPrinterName = Set( 'Printer', 2 ) && Get default Windows printer
hPrinter = 0

If (OpenPrinter( cPrinterName, @hPrinter, 0 ) != 0)
cPaperName = lcNamaPaper
nBufLen = 32 && FORM_INFO_1_Size
cInfo = Replicate( Chr(0), 32 )
nResult = GetPrinterForm( hPrinter, cPaperName, 1, ;
@cInfo, nBufLen, @nBufLen )

If (nResult == 0) && Get printer form failed
nResult = GetLastError()

If (nResult == 1902) && ERROR_INVALID_FORM_NAME
** Custom Printer Form not exist, add the new one
nPaperWidth =22000 / 2 && Paper size is in 1/1000 millimeters
nPaperHeight =317000 / 2

sPaperSize = BinToC( nPaperWidth, '4rs' ) + BinToC( nPaperHeight, '4rs' )
pPaperName = LocalAlloc( 64, 32 )

If (pPaperName != 0)
Sys( 2600, pPaperName, Len( cPaperName ), cPaperName )
cInfo = BinToC( 0, '4rs' ) + BinToC( pPaperName, '4rs' ) + ;
sPaperSize + BinToC( 0, '4rs' ) + BinToC( 0, '4rs' ) + sPaperSize

If (AddPrinterForm( hPrinter, 1, cInfo ) != 0)
? 'Custom paper form (' + cPaperName + ') has been added! '
Else
? 'Error:', GetLastError()
Endif

LocalFree( pPaperName )
Endif

Else
If (nResult == 122) && Insufficient buffer
? 'Error: Custom Paper Form already exist!'
Else
? 'Error: ', nResult
Endif
Endif
Else
? 'Error: ', nResult
Endif
ClosePrinter( hPrinter )
Endif
Endproc

&nbsp;

Procedure Idpaper(lcNamaPaper)
#Define DC_PAPERS 2
#Define DC_PAPERS_Size 2
#Define DC_PAPERNAMES 16
#Define DC_PAPERNAMES_Size 64
Declare Long DeviceCapabilities In WinSpool.drv ;
String cPrinterName, String cPort, Short nCapFlags, ;
String @O_cBuffer, Long pDevMode

Local Array la_Printer[1]
Local ln_Row, ln_Result, ln_I, ln_Index
Local lc_PrinterName, lc_Buffer
Local lc_FindPaperName, lc_PaperName, lc_PaperSizeID
lc_PrinterName = Set( 'Printer', 2 ) && Get default windows printer
= Aprinters( la_Printer )
ln_Row = Ascan( la_Printer, lc_PrinterName, 1, 0, 0, 9 )
ln_Result = DeviceCapabilities( la_Printer[ ln_Row, 1 ], ;
la_Printer[ ln_Row, 2 ], DC_PAPERNAMES, 0, 0 )
If (ln_Result > 0)
ln_Index = -1
lc_FindPaperName = Upper(lcNamaPaper)
lc_Buffer = Replicate( Chr(0), ln_Result * DC_PAPERNAMES_Size )
ln_Result = DeviceCapabilities( la_Printer[ ln_Row, 1 ], ;
la_Printer[ ln_Row, 2 ], DC_PAPERNAMES, @lc_Buffer, 0 )
For ln_I = 0 To ln_Result-1
lc_PaperName = Upper( Substr( lc_Buffer, (ln_I * DC_PAPERNAMES_Size )+1, ;
DC_PAPERNAMES_Size ))
If (lc_FindPaperName $ lc_PaperName)
ln_Index = ln_I
Exit
Endif
Next
If (ln_Index != -1)
** Paper Name found, Get The PaperSize ID
ln_Result = DeviceCapabilities( la_Printer[ ln_Row, 1 ], ;
la_Printer[ ln_Row, 2 ], DC_PAPERS, 0, 0 )
If (ln_Result > 0)
lc_Buffer = Replicate( Chr(0), ln_Result * DC_PAPERS_Size )
ln_Result = DeviceCapabilities( la_Printer[ ln_Row, 1 ], ;
la_Printer[ ln_Row, 2 ], DC_PAPERS, @lc_Buffer, 0 )
lc_PaperSizeID = Substr( lc_Buffer, (ln_Index * DC_PAPERS_Size )+1, DC_PAPERS_Size )

* ? 'PaperSize ID for "' + lc_FindPaperName + '" is', CToBin( lc_PaperSizeID, '2rs' )
Endif
Endif
ENDIF
RETURN CToBin( lc_PaperSizeID, '2rs' )
Endproc

procedure custompaper digunakan untuk setting ukuran kertas makanya ada widht dan height paper, dan idpaper adalah id unix yang dihasilkan dari create custompaper tadi, naa ID paper ini yang nanti akan di replace kedalam report(.frx) info lengkapnya bisa baca disini https://rubahmania.wordpress.com/2016/05/20/custom-pagesize-report-foxpro/

cara memakainya gampang aja

report awal, adalah legal, idpapernya 5

1

selanjutnya coba bikin script di program


Clea
lcNamaPaper='MyCustom - Half A4'
customPaper(lcNamaPaper)
lnPagesize=Idpaper(lcNamaPaper)
?lnPagesize
update tbreport SET nPagesize = lnPagesize WHERE idUser='001'

naa nanti report akan terbentung dengan nama MyCustom – Half A4 dengan widht 22000 dan height 317000 ,

btw hitungan lebar panjang kertas adalah dari milimeter ke inci yang mana 1 milimiter = 0,0393701 inci , baca baca lah ntr paham kq, ok jalankan script diatas, hasilanya

1

dan liat di print setup,

Untitled

kertas dengan nama MyCustom terbentuk , jadi deh 😀

hasilnya,User A (001)

1

sedangkan User B

1

[edit]

penggunaan di form begini,

Capture

di set dulu procedure newpaper.prg di program main 🙂

2

baru deh runningkan formnya hasilnya sama diatas

Ref :

http://hermantan.blogspot.co.id/