function doPushByUserID() { $app_id = addslashes($_POST['app_id']); $key = addslashes($_POST['key']); $ipaddress = $_SERVER['REMOTE_ADDR']; $app = new AppAccount(); if ($app_id == "" || $key == "") { $json['status_code'] = 0; echo json_encode($json); die; } else { $app->getByID($app_id); // $acc = new Account(); // $acc->getByID($app->app_client_id); if ($app->app_token != $key) { $json['status_code'] = 0; $json['status_message'] = "wrong key"; echo json_encode($json); die; } if ($app->app_allowed_ip != "" && $app->app_allowed_ip != $ipaddress) { $json['status_code'] = 0; $json['status_message'] = "wrong ip, your ip is " . $ipaddress; echo json_encode($json); die; } } //actual coding begin here .... //only get device IDS and do it in the other function $ids = addslashes($_POST['ids']); $arrIds = explode(",", $ids); $all = array(); foreach ($arrIds as $id) { $devs = new DeviceModel(); $arrDevs = $devs->getWhere("dev_app_id = '{$app_id}' AND acc_id = '{$id}'"); foreach ($arrDevs as $d) { $all[] = $d->device_id; } } $_POST['devs'] = implode(",", $all); $this->doPushByDevID(); }
function save_old() { $device_id = addslashes($_POST['device_id']); $type = addslashes($_POST['type']); if ($device_id == "" || $type == "") { $json['status_code'] = 0; echo json_encode($json); die; } // $did = $device_id."_".$type; $acc = isset($_POST['acc_id']) ? addslashes($_POST['acc_id']) : 0; $dn = new DeviceModel(); $dnquery = new DeviceModel(); // $dn->getByID($did); // langkah 1 , device ID ada device type ada $arrs = $dnquery->getWhere("device_id = '{$device_id}' AND device_type = '{$type}'"); $dn = $arrs[0]; // pr($arrs); if ($dn->did == "") { // $dn = new DeviceModel(); //langkah 2 ambil account id yg actual if ($acc > 0) { // echo "in"; $arrs = $dnquery->getWhere("acc_id = '{$acc}' AND device_type = '{$type}' AND device_id = '{$device_id}' ORDER BY logindate DESC"); $dn = $arrs[0]; // pr($dn); if (is_object($dn)) { $did = $dn->did; } else { $did = 0; } if (!$did) { //create baru acc id isi $dn = new DeviceModel(); // $dn->did = $did; $dn->device_id = $device_id; $dn->device_type = $type; $dn->acc_id = $acc; $dn->firstlogin = leap_mysqldate(); } else { //hapus semua entry dari account lama // global $db; // $query = "DELETE FROM {$dnquery->table_name} WHERE acc_id = '$acc' AND did != '{$dn->did}'"; // echo $query; // $db->query($query,0); //insert new //kalau acc id ada device id di update $dn->device_id = $device_id; // $dn->acc_id = $acc; $dn->load = 1; } } else { //create baru acc id kosong $dn = new DeviceModel(); // $dn->did = $did; $dn->device_id = $device_id; $dn->device_type = $type; $dn->firstlogin = leap_mysqldate(); // $dn->acc_id = $acc; } } else { //kalau device id ada, acc di update $dn->load = 1; $dn->acc_id = $acc; //untuk hapus jikalau cuman boleh satu... // global $db; // $query = "DELETE FROM {$dnquery->table_name} WHERE acc_id = '$acc' AND did != '{$dn->did}'"; // echo $query; // $db->query($query,0); } $dn->logindate = leap_mysqldate(); // pr($dn); if ($dn->save()) { $json['save_status'] = 1; } else { $json['save_status'] = 0; } $json['status_code'] = 1; echo json_encode($json); die; }
function save() { //IMBAuth::checkOAuth(); $device_id = addslashes($_POST['device_id']); $type = addslashes($_POST['type']); //completion check if ($device_id == "" || $type == "") { $json['status_code'] = 0; $json['status_message'] = "Incomplete Request"; echo json_encode($json); die; } //check account.. $acc = isset($_POST['acc_id']) ? addslashes($_POST['acc_id']) : 0; $res_id = isset($_POST['res_id']) ? addslashes($_POST['res_id']) : 0; // IMBAuth::checkOAuth(); $dn = new DeviceModel(); $dnquery = new DeviceModel(); // langkah 1 , device ID ada device type ada $arrs = $dnquery->getWhere("device_id = '{$device_id}' AND device_type = '{$type}'"); $dn = $arrs[0]; if ($dn->did == "") { $dn = new DeviceModel(); $dn->device_id = $device_id; $dn->device_type = $type; $dn->acc_id = $acc; $dn->firstlogin = leap_mysqldate(); $dn->dev_res_id = $res_id; } else { //kalau device id ada, acc di update $dn->load = 1; $dn->acc_id = $acc; $dn->dev_res_id = $res_id; } $dn->dev_lng = addslashes($_POST['lng']); $dn->dev_lat = addslashes($_POST['lat']); $dn->logindate = leap_mysqldate(); //save user latlong to MasterUser -- 10 May 2016 sendy if (isset($_POST['lat']) && isset($_POST['lng']) && $acc != 0) { $user = new UserModel(); $user->getByID($acc); $user->logindate = leap_mysqldate(); $user->latitude = addslashes($_POST['lat']); $user->longitude = addslashes($_POST['lng']); $user->save(); } //save user District and City to LocationModel -- 26 May 2016 sendy Generic::saveDistrictCityFromLatLng(addslashes($_POST['lat']), addslashes($_POST['lng']), $acc, $type == "cashier"); if ($dn->save()) { $json['save_status'] = 1; $json['version'] = Efiwebsetting::getData('App_Version_' . strtolower($type)); $json['url'] = Efiwebsetting::getData('App_URL_' . strtolower($type)); //logged all device login 19 nov 2015 roy // $logged = new DeviceLogger(); // $logged->log_acc_id = $dn->acc_id; // $logged->log_date = leap_mysqldate(); // $logged->log_dev_id = $dn->device_id; // $logged->log_dev_type = $dn->device_type; // $logged->save(); } else { $json['save_status'] = 0; } $json['status_code'] = 1; if ($_POST['do_not_die']) { return $json; } else { echo json_encode($json); die; } }
static function sendUsingAccountArray($arrAcc, $psn, $isTest = 0) { if ($_GET['test']) { pr($arrAcc); } if ($_GET['test']) { echo "<h1>Push Complete Results</h1>"; } foreach ($arrAcc as $to) { $dev = new DeviceModel(); // $arrD = $dev->getWhere("acc_id = '$to' AND device_type = 'android' ORDER BY logindate DESC"); //kalau dijaddin ga aktif 16 dec 2015 // $arrD = $dev->getWhere("acc_id = '$to' ORDER BY logindate DESC"); $arrD = $dev->getWhere("acc_id = '{$to}' AND dev_active = 1 ORDER BY logindate DESC"); // $json['arrD'] = $arrD; // foreach ($arrD as $d) { // $json['dev'] = $d->device_id; //// if($d->device_id == "")continue; // $hasil = self::push($d->device_id, $msg, $website); // $json['hasil'] = $hasil; // if ($hasil->success > 0) { // $json['bool'] = 1; //// $json['hasil'] = $hasil; // } // } if (count($arrD) > 0) { foreach ($arrD as $ddd) { $devices[] = $ddd; } } else { if ($_GET['test']) { echo "no device id : " . $to . " <br>"; } } } $action = self::getAction($psn); if ($_GET['test']) { echo "action = " . $action . "<br>"; } $array_id = array(); if ($_GET['test']) { echo "<h3>Devices</h3>"; } foreach ($devices as $dev) { if ($_GET['test']) { echo " acc_id : " . $dev->acc_id; echo "<br> dev_id : " . $dev->device_id; echo "<br> type : " . $dev->device_type; echo "<br>"; } $array_id[] = $dev->device_id; } $url2push = Efiwebsetting::getData('PUBLIC_IP') . "WebViewer/messages/" . $psn->camp_id; //penambahan atas permintaan tbs 10 sept 2015, bisa push url if ($psn->camp_url != "") { $url2push = $psn->camp_url; } /* * * PILIHAN antara server luar dan dalam * 27 Nov 2015 * */ $pss = new Pusher(); if ($pss->pakai_server_luar == '1') { $app_id = 1; $app_key = "1qay2wsx"; $push_api_url = "http://push.indomegabyte.com/PushAPI/doPushByDevID"; $devs = implode(",", $array_id); $fields = array('devs' => $devs, 'app_id' => $app_id, 'key' => $app_key, 'camp_id' => $psn->camp_id, 'camp_name' => $psn->camp_name, 'camp_title' => $psn->camp_title, 'camp_url' => $url2push, 'isTest' => $isTest); $headers = array('Content-Type: application/json'); // pr($fields); //"postvar1=value1&postvar2=value2&postvar3=value3" foreach ($fields as $k => $val) { $jadi[] = $k . "=" . $val; } $imp = implode("&", $jadi); // echo http_build_query($fields); // $ch = curl_init(); // curl_setopt($ch, CURLOPT_URL, $push_api_url); // curl_setopt($ch, CURLOPT_POST, true); // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // curl_setopt($ch, CURLOPT_POSTFIELDS, $imp); // $result = json_decode(curl_exec($ch)); // curl_close($ch); // // pr($result); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $push_api_url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields)); // in real life you should use something like: // curl_setopt($ch, CURLOPT_POSTFIELDS, // http_build_query(array('postvar1' => 'value1'))); // receive server response ... curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $server_output = curl_exec($ch); curl_close($ch); // pr($server_output); $ress = json_decode($server_output); if (!isset($_POST['no_echo'])) { echo "<h1>" . $ress->status_message . " Status Code [" . $ress->status_code . "]</h1>"; } $arrhasil = $ress->result; // pr($arrhasil); } elseif ($pss->pakai_server_luar == '2') { //create temporary files to read from $myfile = fopen(_PHOTOPATH . "campaign.txt", "w") or die("Unable to create file!"); $txt = implode(",", $array_id); if (fwrite($myfile, $txt)) { fclose($myfile); $app_id = 1; $app_key = "1qay2wsx"; $push_api_url = "http://push.indomegabyte.com/PushAPI/doPushByDevIDwithFile"; // $push_api_url = "http://localhost:8888/push/PushAPI/doPushByDevIDwithFile"; $devs = Efiwebsetting::getData('PUBLIC_IP') . "uploads/campaign.txt"; // pr($devs); // pr($push_api_url); $fields = array('devs' => $devs, 'app_id' => $app_id, 'key' => $app_key, 'camp_id' => $psn->camp_id, 'camp_name' => $psn->camp_name, 'camp_title' => $psn->camp_title, 'camp_url' => $url2push, 'isTest' => $isTest); $headers = array('Content-Type: application/json'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $push_api_url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $server_output = curl_exec($ch); curl_close($ch); $ress = json_decode($server_output); if (!isset($_POST['no_echo'])) { echo "<h1>" . $ress->status_message . " Status Code [" . $ress->status_code . "]</h1>"; } $arrhasil = $ress->result; // pr($fields); // pr($arrhasil); // pr($server_output); } else { die("Unable to write"); } } else { //after we collected the device ids in an array, kita push $arrhasil = self::push($array_id, $psn->camp_title, $url2push, $action); } if ($_GET['test']) { pr($arrhasil); } if (!isset($_POST['no_echo'])) { echo "<h1>Results</h1>"; } foreach ($arrhasil as $numw => $hasil) { //simpan hasil $gcm = new GCMResult(); $gcm->multicast_id = $hasil->multicast_id; $gcm->success = $hasil->success; $gcm->failure = $hasil->failure; $gcm->results = serialize($hasil->results); $gcm->canonical_ids = $hasil->canonical_ids; $gcm->camp_id = $psn->camp_id; $gcm->gcm_date = leap_mysqldate(); $gcm->gcm_test = $isTest; $gcm->save(); if (!isset($_POST['no_echo'])) { echo "ID : " . $hasil->multicast_id . "<br>"; echo "Success : " . $hasil->success . "<br>"; echo "Failure : " . $hasil->failure . "<br>"; echo "<a target='_blank' href='" . _SPPATH . "PushNotResults/res?id={$psn->camp_id}&token=" . IMBAuth::createOAuth() . "' class='btn btn primary'>Complete Results</a><br><br>"; } $page = 999 * $numw; foreach ($hasil->results as $num => $res) { if (isset($res->error)) { //error $status = 0; $log_text = $res->error; //delete device_id from table $dv = new DeviceModel(); global $db; $q = "DELETE FROM {$dv->table_name} WHERE device_id = '" . $array_id[$page + $num] . "'"; $q = "UPDATE {$dv->table_name} SET dev_active = 0 WHERE device_id = '" . $array_id[$page + $num] . "'"; //coba test.. // echo $q; $del = $db->query($q, 0); if ($_GET['test']) { echo "<br>query : " . $q . "<br>"; echo "delete succ :" . $del; echo "<br>"; } } else { //success $status = 1; $log_text = $res->message_id; } PushLogger::savelog($psn->camp_id, $array_id[$num], $devices[$num]->acc_id, $status, $log_text, $hasil->multicast_id); //disini save camp_id ke device_id dan date //pakai PushLogger Bisa !!! 11 January 2016 } } // foreach($hasil->results as $ // foreach($devices as $dev) { // PushLogger::savelog($psn->camp_id,) // } // echo json_encode($json); // die(); }
function app() { $bulan = addslashes($_GET['m']); if ($bulan == "") { $bulan = date("F Y"); $days_ago = date('Y-m-01'); // hard-coded '01' for first day $days_now = date('Y-m-t'); } else { $bulan = urldecode($bulan); $days_ago = date('Y-m-01', strtotime($bulan)); // hard-coded '01' for first day $days_now = date('Y-m-t', strtotime($bulan)); } $numberDays = cal_days_in_month(CAL_GREGORIAN, date('n', strtotime($bulan)), date('Y', strtotime($bulan))); $days_ago = date('Y-m-01', strtotime($bulan)); // hard-coded '01' for first day $days_now = date('Y-m-01', strtotime('+1 month', strtotime($bulan))); //user acquisitions $ll = new LL_Account(); $arrUserNew = $ll->getWhere("(macc_acquire_date BETWEEN '{$days_ago}' AND '{$days_now}')", "macc_acquire_date"); //new device $dev = new DeviceModel(); $arrDevNew = $dev->getWhere(" (firstlogin BETWEEN '{$days_ago}' AND '{$days_now}') "); //device active $dlog = new DeviceLogger(); $arrDevActive = $dlog->getWhere(" (log_date BETWEEN '{$days_ago}' AND '{$days_now}') "); // count($arrDevActive); //user active $acclog = new LL_AccountLogger(); $arrUserActive = $acclog->getWhere("(log_date BETWEEN '{$days_ago}' AND '{$days_now}')"); // count($arrUserActive); $arrStats["New Users"] = $arrUserNew; $arrStats["Active Users"] = $arrUserActive; $arrStats["New Devices"] = $arrDevNew; $arrStats["Active Devices"] = $arrDevActive; $t = time(); ?> <div class="row"> <div class="col-md-12"> <h1> App Dashboard <small><?php echo $bulan; ?> </small> </h1> <ol class="breadcrumb"> <li> <?php echo Lang::t('Select Timeframe'); ?> </li> <li class="active"> <?php $start = new DateTime('11 months ago'); // So you don't skip February if today is day the 29th, 30th, or 31st $start->modify('first day of this month'); $end = new DateTime(); $interval = new DateInterval('P1M'); $period = new DatePeriod($start, $interval, $end); ?> <select id="apptimeselector_<?php echo $t; ?> "> <?php foreach ($period as $dt) { ?> <option value="<?php echo urlencode($dt->format('F Y')); ?> " <?php if ($dt->format('F Y') == $bulan) { echo "selected"; } ?> > <?php echo $dt->format('F Y') . "<br>"; ?> </option> <?php } ?> </select> <script> $("#apptimeselector_<?php echo $t; ?> ").change(function(){ var slc = $("#apptimeselector_<?php echo $t; ?> ").val(); openLw("App","<?php echo _SPPATH; ?> BIWebProd/app?m="+slc,"fade"); }); </script> </li> </ol> </div> </div> <div class="row"> <div class="col-md-3"> <div class="small-box bg-aqua"> <div class="inner"> <h3><?php echo count($arrUserNew); ?> </h3> <p>New Users</p> </div> <div class="icon"> <i class="ion ion-bag"></i> </div> <!-- <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>--> </div> </div> <div class="col-md-3"> <div class="small-box bg-green"> <div class="inner"> <h3><?php echo count($arrUserActive); ?> </h3> <p>Active Users</p> </div> <div class="icon"> <i class="ion ion-stats-bars"></i> </div> <!-- <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>--> </div> </div> <div class="col-md-3"> <div class="small-box bg-yellow"> <div class="inner"> <h3><?php echo count($arrDevNew); ?> </h3> <p>New Devices</p> </div> <div class="icon"> <i class="ion ion-stats-bars"></i> </div> <!-- <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>--> </div> </div> <div class="col-md-3"> <div class="small-box bg-red"> <div class="inner"> <?php ?> <h3><?php echo count($arrDevActive); ?> </h3> <p>Active Devices</p> </div> <div class="icon"> <i class="ion ion-stats-bars"></i> </div> <!-- <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>--> </div> </div> </div> <div class="row"> <div class="col-md-12"> <div class="box box-default"> <div class="box-header with-border"> <h3 class="box-title">User Stats</h3> <div class="box-tools pull-right"> <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i> </button> <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button> </div> </div> <div class="box-body chart-responsive"> <?php // $days_ago = date('Y-m-d', strtotime('-30 days', time())); // $days_now = date("Y-m-d"); $data = self::getAppStats($arrStats, $days_ago, $days_now); ?> </div> <!-- /.box-body --> </div> </div> </div> <div class="row"> <?php $arrDType = array(); foreach ($arrDevActive as $de) { $arrDType[$de->log_dev_type][] = $de; } $arrColor = array("#00a65a", "#00c0ef"); foreach ($arrDType as $type => $arrDe) { $c = new Charting(); $c->color = array_pop($arrColor); $c->label = $type; $c->value = count($arrDe); $totalanDevType[$type] = $c->value; $arrData[] = $c; } // pr($arrData); ?> <div class="col-md-6"><?php Charting::morrisDonut("300px", $arrData, 1, "Device Type", "default"); ?> </div> <div class="col-md-6"> <div class="box box-default"> <div class="box-header with-border"> <h3 class="box-title">Average</h3> <div class="box-tools pull-right"> <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i> </button> <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button> </div> </div> <div class="box-body chart-responsive"> <div class="average" style="padding: 20px;"> <?php // pr($data); $maxUsers = max($data['New Users']); $maxActiveUsers = max($data['Active Users']); $maxNewDevice = max($data['New Devices']); $maxActiveDevice = max($data['Active Devices']); ?> <p class="text-center"> <strong></strong> </p> <!-- /.progress-group --> <div class="progress-group"> <span class="progress-text">New Users per Day</span> <span class="progress-number"><b><?php echo round(count($arrUserNew) / $numberDays, 2); ?> </b>/<?php echo $maxUsers; ?> </span> <div class="progress sm"> <?php $percent = ceil(count($arrUserNew) / $numberDays) / $maxUsers * 100; ?> <div class="progress-bar progress-bar-red" style="width: <?php echo $percent; ?> %"></div> </div> </div> <!-- /.progress-group --> <div class="progress-group"> <?php $rata2 = round(count($arrUserActive) / $numberDays, 2); $percent = round($rata2 / $maxActiveUsers * 100); ?> <span class="progress-text">Active Users per Day</span> <span class="progress-number"><b><?php echo $rata2; ?> </b>/<?php echo $maxActiveUsers; ?> </span> <div class="progress sm"> <div class="progress-bar progress-bar-yellow" style="width: <?php echo $percent; ?> %"></div> </div> </div> <!-- /.progress-group --> <div class="progress-group"> <?php $rata2 = round(count($arrDevNew) / $numberDays, 2); $percent = round($rata2 / $maxNewDevice * 100); ?> <span class="progress-text">New Device per Day</span> <span class="progress-number"><b><?php echo $rata2; ?> </b>/<?php echo $maxNewDevice; ?> </span> <div class="progress sm"> <div class="progress-bar progress-bar-red" style="width: <?php echo $percent; ?> %"></div> </div> </div> <!-- /.progress-group --> <!-- /.progress-group --> <div class="progress-group"> <?php $rata2 = round(count($arrDevActive) / $numberDays, 2); $percent = round($rata2 / $maxActiveDevice * 100); ?> <span class="progress-text">Active Device per Day</span> <span class="progress-number"><b><?php echo $rata2; ?> </b>/<?php echo $maxActiveDevice; ?> </span> <div class="progress sm"> <div class="progress-bar progress-bar-yellow" style="width: <?php echo $percent; ?> %"></div> </div> </div> <!-- /.progress-group --> <div class="progress-group"> <span class="progress-text">Android vs iOS</span> <span class="progress-number"><b><?php echo $totalanDevType['android']; ?> </b>/<?php echo $totalanDevType['android'] + $totalanDevType['ios']; ?> </span> <div class="progress sm"> <?php $percent = round($totalanDevType['android'] / ($totalanDevType['android'] + $totalanDevType['ios']) * 100); ?> <div class="progress-bar progress-bar-aqua" style="width: <?php echo $percent; ?> %"></div> </div> </div> <!-- /.progress-group --> <div class="progress-group"> <span class="progress-text">iOS vs Android</span> <span class="progress-number"><b><?php echo $totalanDevType['ios']; ?> </b>/<?php echo $totalanDevType['android'] + $totalanDevType['ios']; ?> </span> <div class="progress sm"> <?php $percent = round($totalanDevType['ios'] / ($totalanDevType['android'] + $totalanDevType['ios']) * 100); ?> <div class="progress-bar progress-bar-green" style="width: <?php echo $percent; ?> %"></div> </div> </div> </div> </div> <!-- /.box-body --> </div> </div> </div> <style> ul.legend li{ list-style: none; line-height: 30px; } ul.legend li div{ float: left; margin-top: 10px; margin-right: 15px; } .legend-item{ float: left; margin: 10px; line-height: 30px; margin-right: 5px; } .legend-item div{ float: left; margin-top: 10px; margin-right: 5px; } .breadcrumb { padding: 8px 15px; margin-bottom: 20px; list-style: none; background-color: #f5f5f5; border-radius: 4px; } .breadcrumb { float: right; background: transparent; margin-top: 0; margin-bottom: 0; font-size: 12px; padding: 7px 5px; position: absolute; top: 15px; right: 10px; border-radius: 2px; } </style> <?php }
function pertama() { $app_id = addslashes($_POST['app_id']); $key = addslashes($_POST['key']); $device_id = addslashes($_POST['device_id']); $type = addslashes($_POST['type']); $lat = addslashes($_POST['lat']); $lng = addslashes($_POST['long']); if ($device_id == "" || $type == "") { $json['status_code'] = 0; echo json_encode($json); die; } if ($app_id == "" || $key == "") { $json['status_code'] = 0; echo json_encode($json); die; } else { //check if this app belongs to right owner $app = new AppAccount(); $app->getByID($app_id); // $acc = new Account(); // $acc->getByID($app->app_client_id); if ($app->app_token != $key) { $json['status_code'] = 0; $json['status_message'] = "wrong key"; echo json_encode($json); die; } } $log_page_id = addslashes($_POST['page_id']); $acc = isset($_POST['acc_id']) ? addslashes($_POST['acc_id']) : 0; $dn = new DeviceModel(); $dnquery = new DeviceModel(); // langkah 1 , device ID ada device type ada $arrs = $dnquery->getWhere("device_id = '{$device_id}' AND device_type = '{$type}'"); $dn = $arrs[0]; if ($dn->did == "") { $dn = new DeviceModel(); $dn->device_id = $device_id; $dn->device_type = $type; $dn->acc_id = $acc; $dn->firstlogin = leap_mysqldate(); $dn->dev_lat = $lat; $dn->dev_lng = $lng; $dn->dev_app_id = $app_id; } else { //kalau device id ada, acc di update $dn->load = 1; $dn->acc_id = $acc; } $dn->dev_lng = $lng; $dn->dev_app_id = $app_id; $dn->logindate = leap_mysqldate(); if ($dn->save()) { $json['save_status'] = 1; //logged all device login 19 nov 2015 roy $logged = new DeviceLogger(); $logged->log_acc_id = $dn->acc_id; $logged->log_date = leap_mysqldate(); $logged->log_dev_id = $dn->device_id; $logged->log_dev_type = $dn->device_type; $logged->log_app_id = $app_id; $logged->log_lat = $lat; $logged->log_lng = $lng; $logged->log_page_id = $log_page_id; $logged->save(); } else { $json['save_status'] = 0; } $json['status_code'] = 1; echo json_encode($json); die; }
function send() { //pr($_POST); $json = array(); $json['bool'] = 0; //check if url valid $website = addslashes($_POST["action"]); if ($website != "") { if (!preg_match("/\\b(?:(?:https?|ftp):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i", $website)) { $json['err'][] = "Invalid URL"; } } $msg = addslashes($_POST['msg']); if ($msg == "") { $json['err'][] = "Invalid Msg"; } $to = addslashes($_POST['to']); if ($to == "") { $json['err'][] = "Invalid Acc"; } if (count($json['err']) < 1) { $dev = new DeviceModel(); $arrD = $dev->getWhere("acc_id = '{$to}' AND device_type = 'android' ORDER BY did DESC LIMIT 0,1"); // $json['arrD'] = $arrD; foreach ($arrD as $d) { $json['dev'] = $d->device_id; // if($d->device_id == "")continue; $hasil = self::push($d->device_id, $msg, $website); // $json['hasil'] = $hasil; if ($hasil->success > 0) { $json['bool'] = 1; // $json['hasil'] = $hasil; } } if (!$json['bool']) { $json['err'][] = "Invalid Device ID"; } } echo json_encode($json); die; }
static function sendUsingArrayAcc($array_acc, $psn, $app, $isTest = 0) { $filtered = trim(rtrim($array_acc)); $dev = new DeviceModel(); $arrDevs = array(); if ($filtered == "*") { $arrDevs = $dev->getWhere(" dev_not_send = 0 "); // $dev->getAll(); } else { $accFilter = explode(",", $filtered); foreach ($accFilter as $acc_ids) { $acc_ids = trim(rtrim($acc_ids)); $filtext[] = "camp_client_id = '{$acc_ids}'"; } $imp = implode(" OR ", $filtext); $arrDevs = $dev->getWhere("(" . $imp . ") AND dev_not_send = 0 "); } //self::sendUsingAccountArray($arrAcc, $psn); $array_id = array(); if (count($arrDevs) > 0) { foreach ($arrDevs as $dev) { if ($_GET['test']) { echo " acc_id : " . $dev->acc_id; echo "<br> dev_id : " . $dev->device_id; echo "<br> type : " . $dev->device_type; echo "<br>"; } $array_id[] = $dev->device_id; } $url2push = _BPATH . "WebViewer/messages/" . $psn->camp_id; $arrhasil = self::pushAfteriOS($array_id, $psn->camp_title, $url2push, $app); self::simpanHasilGCM($arrhasil, $psn, $array_id, $arrDevs, $app, $isTest); } }
static function sendUsingAccountArray($arrAcc, $psn, $isTest = 0) { if ($_GET['test']) { pr($arrAcc); } if ($_GET['test']) { echo "<h1>Push Complete Results</h1>"; } foreach ($arrAcc as $to) { $dev = new DeviceModel(); // $arrD = $dev->getWhere("acc_id = '$to' AND device_type = 'android' ORDER BY logindate DESC"); $arrD = $dev->getWhere("acc_id = '{$to}' ORDER BY logindate DESC"); // $json['arrD'] = $arrD; // foreach ($arrD as $d) { // $json['dev'] = $d->device_id; //// if($d->device_id == "")continue; // $hasil = self::push($d->device_id, $msg, $website); // $json['hasil'] = $hasil; // if ($hasil->success > 0) { // $json['bool'] = 1; //// $json['hasil'] = $hasil; // } // } if (count($arrD) > 0) { foreach ($arrD as $ddd) { $devices[] = $ddd; } } else { if ($_GET['test']) { echo "no device id : " . $to . " <br>"; } } } $action = self::getAction($psn); if ($_GET['test']) { echo "action = " . $action . "<br>"; } $array_id = array(); if ($_GET['test']) { echo "<h3>Devices</h3>"; } foreach ($devices as $dev) { if ($_GET['test']) { echo " acc_id : " . $dev->acc_id; echo "<br> dev_id : " . $dev->device_id; echo "<br> type : " . $dev->device_type; echo "<br>"; } $array_id[] = $dev->device_id; } $url2push = Efiwebsetting::getData('PUBLIC_IP') . "WebViewer/messages/" . $psn->camp_id; //penambahan atas permintaan tbs 10 sept 2015, bisa push url if ($psn->camp_url != "") { $url2push = $psn->camp_url; } //after we collected the device ids in an array, kita push $arrhasil = self::push($array_id, $psn->camp_title, $url2push, $action); if ($_GET['test']) { pr($arrhasil); } echo "<h1>Results</h1>"; foreach ($arrhasil as $numw => $hasil) { //simpan hasil $gcm = new GCMResult(); $gcm->multicast_id = $hasil->multicast_id; $gcm->success = $hasil->success; $gcm->failure = $hasil->failure; $gcm->results = serialize($hasil->results); $gcm->canonical_ids = $hasil->canonical_ids; $gcm->camp_id = $psn->camp_id; $gcm->gcm_date = leap_mysqldate(); $gcm->gcm_test = $isTest; $gcm->save(); echo "ID : " . $hasil->multicast_id . "<br>"; echo "Success : " . $hasil->success . "<br>"; echo "Failure : " . $hasil->failure . "<br>"; echo "<a target='_blank' href='" . _SPPATH . "PushNotResults/res?id={$psn->camp_id}&token=" . IMBAuth::createOAuth() . "' class='btn btn primary'>Complete Results</a><br><br>"; $page = 999 * $numw; foreach ($hasil->results as $num => $res) { if (isset($res->error)) { //error $status = 0; $log_text = $res->error; //delete device_id from table $dv = new DeviceModel(); global $db; $q = "DELETE FROM {$dv->table_name} WHERE device_id = '" . $array_id[$page + $num] . "'"; if ($_GET['test']) { echo "<br>query : " . $q . "<br>"; echo "delete succ :" . $db->query($q, 0); echo "<br>"; } } else { //success $status = 1; $log_text = $res->message_id; } PushLogger::savelog($psn->camp_id, $array_id[$num], $devices[$num]->acc_id, $status, $log_text, $hasil->multicast_id); } } // foreach($hasil->results as $ // foreach($devices as $dev) { // PushLogger::savelog($psn->camp_id,) // } // echo json_encode($json); // die(); }
function kitchenMR() { $ids = addslashes(trim(rtrim($_POST['ids']))); // $api = "AIzaSyBKvJHG89dP6BHXgcevpXruM8AfEHQt3UA"; $api = "AIzaSyArfDu9suLpmTLdVEiubDLZpSz3cWreK_0"; $exp = explode(",", $ids); foreach ($exp as $e) { $id = trim(rtrim($e)); $imp[] = "dev_res_id = '{$id}'"; } $implode = implode(" OR ", $imp); $devModel = new DeviceModel(); $arrDev = $devModel->getWhere("device_type = 'kitchen' AND ({$implode})"); $json = PusherSatuan::sendUsingDeviceIDs($arrDev, $api, $_POST['msg'], $_POST['json'], $_POST['type'], "res"); return $json; }
function save() { $device_id = addslashes($_POST['device_id']); $type = addslashes($_POST['type']); $app_id = isset($_POST['app_id']) ? addslashes($_POST['app_id']) : 0; //completion check if ($device_id == "" || $type == "" || $app_id == 0) { $json['status_code'] = 0; $json['status_message'] = "Incomplete Request"; echo json_encode($json); die; } $appAcc = new AppAccount(); $appAcc->getByID($app_id); //verify app active if ($appAcc->app_active != 2) { $json['status_code'] = 0; $json['status_message'] = "Please activate App"; echo json_encode($json); die; } //verify token $token = addslashes($_POST['app_token']); if ($token != $appAcc->app_token) { $json['status_code'] = 0; $json['status_message'] = "Token Mismatched"; echo json_encode($json); die; } //check account.. $acc = isset($_POST['acc_id']) ? addslashes($_POST['acc_id']) : 0; IMBAuth::checkOAuth(); $dn = new DeviceModel(); $dnquery = new DeviceModel(); // langkah 1 , device ID ada device type ada $arrs = $dnquery->getWhere("device_id = '{$device_id}' AND device_type = '{$type}' AND dev_app_id = '{$app_id}'"); $dn = $arrs[0]; if ($dn->did == "") { $dn = new DeviceModel(); $dn->device_id = $device_id; $dn->device_type = $type; $dn->acc_id = $acc; $dn->firstlogin = leap_mysqldate(); $dn->dev_app_id = $app_id; } else { //kalau device id ada, acc di update $dn->load = 1; $dn->acc_id = $acc; } $dn->dev_lng = addslashes($_POST['lng']); $dn->dev_lat = addslashes($_POST['lat']); $dn->logindate = leap_mysqldate(); if ($dn->save()) { $json['save_status'] = 1; //logged all device login 19 nov 2015 roy // $logged = new DeviceLogger(); // $logged->log_acc_id = $dn->acc_id; // $logged->log_date = leap_mysqldate(); // $logged->log_dev_id = $dn->device_id; // $logged->log_dev_type = $dn->device_type; // $logged->save(); } else { $json['save_status'] = 0; } $json['status_code'] = 1; echo json_encode($json); die; }
/** * load数据并给与权限判断 */ protected static function loadList($p_where = null, $p_order = null, $p_pageIndex = null, $p_pageSize = null, &$p_countThis = null, $isDetail = false) { $tmpResult = parent::loadList($p_where, $p_order, $p_pageIndex, $p_pageSize, $p_countThis, $isDetail); if (is_array($tmpResult) && array_key_exists('errorCode', $tmpResult)) { return $tmpResult; } switch ($auth = static::getAuthIfUserCanDoIt(Utility::getCurrentUserID(), $isDetail ? 'detail' : 'list', $tmpResult)) { case 'admin': //有管理权限 //有管理权限 case 'self': //作者 break; case 'normal': //正常用户 //正常用户 case 'draft': //未激活 //未激活 case 'pending': //待审禁言 //待审禁言 case 'disabled': //封号 //封号 case 'visitor': //游客 if ($isDetail != 'mydevice') { return Utility::getArrayForResults(RUNTIME_CODE_ERROR_NO_AUTH, '您没有权限执行该操作'); } break; default: return Utility::getArrayForResults(RUNTIME_CODE_ERROR_NO_AUTH, '您没有权限执行该操作'); break; } DeviceModel::$authViewDisabled = static::$authViewDisabledList[$auth]; return $tmpResult; }