static function kerjakan($psn) { //cek apakah ada acc_id, kalau ada..forget filter $cols = "macc_id,macc_first_name,macc_last_name"; $acc = $psn->camp_acc_id; if ($acc != "" || $psn->camp_account_file != "") { $arrAcc = array(); if ($acc != "") { $exp = explode(",", $psn->camp_acc_id); foreach ($exp as $ac) { $arrAcc[] = trim(rtrim($ac)); } //from acc get device ID // self::sendUsingAccountArray($arrAcc, $psn); } if ($psn->camp_account_file != "") { $row = 1; $if = new InputFileModel(); // $arrAcc = array(); if (($handle = fopen($if->upload_location . $psn->camp_account_file, "r")) !== FALSE) { $csv = fread($handle, filesize($if->upload_location . $psn->camp_account_file)); $arrsem = explode(",", $csv); foreach ($arrsem as $acs) { $arrAcc[] = trim(rtrim($acs)); } // while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { // // $arrAcc[] = trim(rtrim($data[0])); // // } fclose($handle); } // pr($arrAcc); //from acc get device ID // self::sendUsingAccountArray($arrAcc, $psn); // die(); } self::sendUsingAccountArray($arrAcc, $psn); } else { //bukan acc, brati filter aktif //cek contradictives constraints $arrwhere = array(); //gender check $query_gender = ""; if ($psn->camp_filter_gender != '0') { if ($psn->camp_filter_gender == '1') { $query_gender = "macc_gender = 'Female'"; } else { $query_gender = "macc_gender = 'Male'"; } $arrwhere[] = $query_gender; } //tier check $query_tier = ""; if ($psn->camp_filter_tier != '0') { if ($psn->camp_filter_tier == '1') { //stampcard $query_tier = "(macc_member_type = 'STC')"; } elseif ($psn->camp_filter_tier == '2') { //club $query_tier = "macc_member_tier = 'LYB Member'"; } elseif ($psn->camp_filter_tier == '3') { //fan $query_tier = "macc_member_tier = 'Fan'"; } else { //all lyb // $query_tier = "(macc_member_tier = 'LYB Member' OR macc_member_tier = 'Fan')"; $query_tier = "(macc_member_tier = 'LYB Member' OR macc_member_tier = 'Fan')"; } $arrwhere[] = $query_tier; } //city check $query_city = ""; if ($psn->camp_filter_city != 'all') { $query_city = "macc_address_city = '{$psn->camp_filter_city}' "; $arrwhere[] = $query_city; } //birthday cek //camp_filter_bday $query_bday = ""; if ($psn->camp_filter_bday != '0') { if ($psn->camp_filter_bday == '1') { //has birthday today $query_bday = "macc_dob = CURDATE()"; } else { //today not his/her bday $query_bday = "macc_dob != CURDATE()"; } $arrwhere[] = $query_bday; } //camp age cek //using inputfilter.. $query_age = ""; if ($psn->camp_filter_age != "") { $exp = explode("__", $psn->camp_filter_age); // $cols = "macc_id,TIMESTAMPDIFF(YEAR,macc_dob,CURDATE()) AS age"; if ($exp[0] == "=") { $query_age = " TIMESTAMPDIFF(YEAR,macc_dob,CURDATE()) = " . $exp[1]; } if ($exp[0] == "!=") { $query_age = " TIMESTAMPDIFF(YEAR,macc_dob,CURDATE()) != " . $exp[1]; } if ($exp[0] == "<") { $query_age = " TIMESTAMPDIFF(YEAR,macc_dob,CURDATE()) < " . $exp[1]; } if ($exp[0] == ">") { $query_age = " TIMESTAMPDIFF(YEAR,macc_dob,CURDATE()) > " . $exp[1]; } if ($exp[0] == "<=") { $query_age = " TIMESTAMPDIFF(YEAR,macc_dob,CURDATE()) <= " . $exp[1]; } if ($exp[0] == ">=") { $query_age = " TIMESTAMPDIFF(YEAR,macc_dob,CURDATE()) >= " . $exp[1]; } $arrwhere[] = $query_age; } //now calculate the query $acc = new LL_Account(); $arrAcc = array(); // pr($arrwhere); // echo $cols; if (count($arrwhere) > 0) { $where = implode(" AND ", $arrwhere); echo $where; $arrAcc = $acc->getWhere($where, $cols); } else { $arrAcc = $acc->getAll(); } $arrSend = array(); //masukan ke 1 array foreach ($arrAcc as $cc) { $arrSend[] = $cc->macc_id; } //from acc get device ID self::sendUsingAccountArray($arrSend, $psn); } }
function testPush() { $acc = new LL_Account(); $arrAcc = $acc->getAll(); $inputID = "to"; ?> <form method="post" action="<?php echo _SPPATH; ?> PushNotBE/send" id="sendPN"> <div id="formgroup" class="form-group"> <label for="<?php echo $inputID; ?> " class="col-sm-2 control-label"><?php echo Lang::t($inputID); ?> </label> <div class="col-sm-10"> <select class="form-control" id="<?php echo $inputID; ?> " name="<?php echo $inputID; ?> "> <?php foreach ($arrAcc as $acc) { ?> <option value="<?php echo $acc->macc_id; ?> "><?php echo $acc->macc_first_name; ?> <?php echo $acc->macc_last_name; ?> </option> <?php } ?> </select> <span class="help-block" id="warning_<?php echo $inputID; ?> "></span> </div> <?php $inputID = 'msg'; ?> <label for="<?php echo $inputID; ?> " class="col-sm-2 control-label"><?php echo Lang::t($inputID); ?> </label> <div class="col-sm-10"> <input class="form-control" type="text" id="<?php echo $inputID; ?> " name="<?php echo $inputID; ?> " placeholder="<?php echo Lang::t($inputID); ?> "> <span class="help-block" id="warning_<?php echo $inputID; ?> "></span> </div> <?php $inputID = 'action'; ?> <div style="display: none;"> <label for="<?php echo $inputID; ?> " class="col-sm-2 control-label"><?php echo Lang::t($inputID); ?> </label> <div class="col-sm-10" > <input class="form-control" type="url" id="<?php echo $inputID; ?> " name="<?php echo $inputID; ?> " placeholder="<?php echo Lang::t($inputID); ?> "> <span class="help-block" id="warning_<?php echo $inputID; ?> "></span> </div> </div> </div> <button type="submit" class="btn btn-default btn-lg"><?php echo Lang::t('Send'); ?> </button> </form> <script type="text/javascript"> // console.log(array_rte); $("#sendPN").submit(function (event) { //alert( "Handler for .submit() called." ); // Stop form from submitting normally event.preventDefault(); // Get some values from elements on the page: var $form = $(this), url = $form.attr("action"); // Send the data using post var posting = $.post(url, $form.serialize(), function (data) { // alert(data); console.log( data ); // John //console.log( data.bool ); // 2pm if(data.bool){ alert('Success'); }else{ var obj = data.err; // var tim = data.timeId; //console.log( obj ); for (var property in obj) { // alert(property); if (obj.hasOwnProperty(property)) { alert(obj[property]); } } } },'json'); }); </script> <?php }