Example #1
0
 /**
  * @before _secure
  */
 public function postbacks()
 {
     $this->seo(["title" => "Network: PostBacks"]);
     $view = $this->getActionView();
     $postbacks = \PostBack::all(['org_id = ?' => $this->org->id]);
     $view->set('postbacks', $postbacks);
 }
Example #2
0
 /**
  * @before _secure
  * @todo @Faizan_Ayubi Remove UNSAFE Actions from GET Request
  */
 public function postback($id)
 {
     $this->JSONView();
     $view = $this->getActionView();
     $postback = PostBack::first(["id" => $id, "org_id" => $this->org->_id]);
     if ($postback) {
         switch (strtolower(RM::type())) {
             case 'delete':
                 $postback->delete();
                 $view->set('message', 'PostBack Deleted Successfully');
                 break;
             case 'post':
                 $postback->live = (int) RM::post("live");
                 $postback->save();
                 $view->set('message', 'PostBack Updated Successfully');
                 break;
         }
     } else {
         $view->set('message', "Invalid Request!!");
     }
 }
Example #3
0
 protected function _postback($case, $extra = [])
 {
     $view = $this->getActionView();
     switch ($case) {
         case 'add':
             $search = ["org_id" => $this->org->_id, "user_id" => $this->user->_id, "event" => RM::post("event")];
             if (isset($extra['ad'])) {
                 $search["ad_id"] = $extra['ad']->_id;
             }
             $foundPostback = PostBack::first($search);
             if (RM::post('action') === 'addCallback' && !$foundPostback) {
                 $postback = new PostBack(array_merge($search, ["data" => RM::post("data"), "type" => RM::post("type")]));
                 $postback->save();
                 $view->set('message', 'Postback Saved Successfully');
             } else {
                 $view->set('message', 'Postback already added');
             }
             break;
         case 'delete':
             $postback = PostBack::first(["_id" => RM::get("postback_id"), "user_id" => $this->user->_id, "org_id" => $this->org->_id]);
             // check for valid request as a fallback
             if (RM::type() === 'DELETE' && RM::get('removeCallback') && $postback) {
                 $postback->delete();
                 $view->set('message', "Postback removed!!");
             } else {
                 $view->set('message', "Invalid Request!!");
             }
             break;
         case 'show':
             $query = ['user_id' => $this->user->_id, 'org_id' => $this->org->_id];
             if (isset($extra['ad'])) {
                 $query["ad_id"] = $extra['ad']->_id;
                 $postbacks = PostBack::all($query);
             } else {
                 $postbacks = PostBack::all($query);
                 $ans = [];
                 foreach ($postbacks as $p) {
                     if (!$p->ad_id) {
                         $ans[$p->_id] = $p;
                     }
                 }
                 $postbacks = $ans;
             }
             $view->set('postbacks', $postbacks);
             break;
     }
 }