function messages($args)
 {
     list($id) = $args;
     $nn = new PushNotCamp();
     $nn->getByID($id);
     self::template(stripslashes($nn->camp_msg));
 }
 public static function pushbyID($id)
 {
     $psn = new PushNotCamp();
     $psn->getByID($id);
     self::kerjakan($psn);
     $psn->camp_status = 1;
     $psn->load = 1;
     //TBD uncomment line dibawah kalau production
     return $psn->save();
 }
 function pusher()
 {
     IMBAuth::checkOAuth();
     //        pr($_POST);
     if ($_POST['ids'] == "") {
         die("Please insert Customer ID");
     }
     if ($_POST['camp_id'] == "") {
         die("Please insert Campaign ID");
     }
     $ids = addslashes($_POST['ids']);
     $ps = new PushNotCamp();
     $ps->getByID(addslashes($_POST['camp_id']));
     $exp = explode(",", $ids);
     $arrAcc = array();
     foreach ($exp as $ac) {
         $arrAcc[] = trim(rtrim($ac));
     }
     //from acc get device ID
     Pusher::sendUsingAccountArray($arrAcc, $ps, 1);
     //1 for testing
 }
 function pusher()
 {
     IMBAuth::checkOAuth();
     //        pr($_POST);
     //        if($_POST['ids'] == "")die("Please insert Customer ID");
     if ($_POST['camp_id'] == "") {
         die("Please insert Campaign ID");
     }
     //        $ids = addslashes($_POST['ids']);
     $ps = new PushNotCamp();
     $ps->getByID(addslashes($_POST['camp_id']));
     $app = new AppAccount();
     $app->getByID($ps->camp_client_id);
     $arrAcc = $ps->camp_client_id;
     //from acc get device ID
     Pusher::sendUsingArrayAcc($arrAcc, $ps, $app, 1);
     //1 for testing
 }
 public function deletePush()
 {
     IMBAuth::checkOAuth();
     $id = addslashes($_POST['push_id']);
     $acc_id = addslashes($_POST['acc_id']);
     $user_token = addslashes($_POST['user_token']);
     $acc = new Account();
     $acc->getByID($acc_id);
     //        echo md5($acc->admin_email.$acc->admin_password);
     if (md5($acc->admin_email . $acc->admin_password) != $user_token) {
         $json['status_code'] = 0;
         $json['status_message'] = "Token Mismatched";
         echo json_encode($json);
         die;
     }
     $push = new PushNotCamp();
     $push->getByID($id);
     if ($push->camp_client_id == $acc_id) {
         //delete
         $push->delete($id);
         $this->getMyPushes();
         //            $json['status_code'] = 1;
         //            $json['status_message'] = "Success";
         //            echo json_encode($json);
         //            die();
     } else {
         $json['status_code'] = 0;
         $json['status_message'] = "Ownership Mismatched";
         echo json_encode($json);
         die;
     }
 }
 public function exportIt($return)
 {
     $id = addslashes($_GET['cid']);
     //        echo $id;
     if ($id == "" || $id < 1) {
         die("no id");
     }
     $camp = new PushNotCamp();
     $camp->getByID($id);
     $arrStatus = array("0" => "Not Pushed", "1" => "Pushed");
     if ($camp->camp_app_id != AppAccount::getAppID()) {
         die("camp mismatched");
     }
     //        pr($camp);
     $onDate = "";
     if ($camp->camp_status == 1) {
         $onDate = " on " . indonesian_date($camp->camp_send_date);
     }
     //hitung openrate dll
     $targetedDev = count(explode(",", $camp->camp_dev_ids));
     $gcm = new GCMResult();
     $arrGCM = $gcm->getWhere("camp_id = '{$id}' ORDER BY gcm_date DESC");
     $succ = 0;
     $fail = 0;
     $seen_by = 0;
     foreach ($arrGCM as $cc) {
         $succ += $cc->success;
         $fail += $cc->failure;
         $seen_by += $cc->seen_by;
     }
     $openrate = round($seen_by / $succ * 100, 3);
     $del = round($succ / ($succ + $fail) * 100, 3);
     $filename = urlencode(str_replace(" ", "_", $camp->camp_name)) . "_" . date('Ymd') . ".xls";
     header("Content-Disposition: attachment; filename=\"{$filename}\"");
     header("Content-Type: application/vnd.ms-excel");
     $flag = false;
     print "Campaign Name : \t" . $camp->camp_title;
     //judul
     print "\n";
     print "Status : \t" . $arrStatus[$camp->camp_status] . $onDate;
     //status and delieverd date
     print "\n";
     print "Content : \t" . $camp->camp_title;
     print "\n";
     print "Open Rate : \t" . $openrate;
     print "\n";
     print "Seen By : \t" . $seen_by;
     print "\n";
     print "Deliverable Percentage : \t" . $del;
     print "\n";
     print "Targeted Devices : \t" . $targetedDev;
     print "\n";
     print "Success : \t" . $succ;
     print "\n";
     print "Failed : \t" . $fail;
     print "\n";
     print "\n";
     $logs = new PushLogger();
     $objs = $logs->getWhere("log_camp_id = '{$id}'");
     $filter = explode(",", $logs->exportList);
     foreach ($objs as $key => $obj) {
         foreach ($obj as $name => $value) {
             if (in_array($name, $filter)) {
                 echo Lang::t($name) . "\t";
             }
         }
         break;
     }
     print "\n";
     foreach ($objs as $key => $obj) {
         foreach ($obj as $name => $value) {
             if (in_array($name, $filter)) {
                 echo $value . "\t";
             }
         }
         print "\n";
     }
     exit;
 }
 function messages($args)
 {
     list($id) = $args;
     $nn = new PushNotCamp();
     $nn->getByID($id);
     self::templateAppear($nn);
 }