Esempio n. 1
0
 public function togglefollowAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $uid = $this->session->userid;
     $id = isset($_GET["id"]) ? $_GET["id"] : "";
     $entryid = isset($_GET["entryid"]) ? $_GET["entryid"] : "";
     if (is_numeric($id) == false) {
         $id = isset($_GET["entryid"]) ? $_GET["entryid"] : "";
     }
     if ($_SERVER['REQUEST_METHOD'] !== "GET" || is_numeric($uid) == false || is_numeric($id) == false) {
         header("Status: 404 Not Found");
         return;
     }
     //Check if user wants to unsubscribe.
     //First check if given id is a mail subscription
     $subsc = null;
     $subscriptions = new Default_Model_MailSubscriptions();
     $subscriptions->filter->id->equals($id)->and($subscriptions->filter->researcherid->equals($uid));
     if (count($subscriptions->items) == 0) {
         //else check if there is a subscription by application id
         $subscriptions = new Default_Model_MailSubscriptions();
         $flt = "=application.id:" . $id . " id:SYSTAG_FOLLOW";
         $subscriptions->filter->flt->ilike($flt)->and($subscriptions->filter->researcherid->equals($uid));
     }
     //Check if subscription is found and unsubscribe
     if (count($subscriptions->items) > 0) {
         $subsc = $subscriptions->items[0];
         $_GET["id"] = $subsc->id;
         $_GET["pwd"] = md5($subsc->unsubscribePassword);
         $_GET["src"] = "ui";
         require_once "NewsController.php";
         $news = new NewsController($this->getRequest(), $this->getResponse(), $this->getInvokeArgs());
         $news->unsubscribeAction();
         return;
     }
     //User wants to subscribe an application
     //Check if application exists
     $apps = new Default_Model_Applications();
     $id = is_numeric($entryid) ? $entryid : $id;
     $apps->filter->id->equals($id);
     if (count($apps->items) == 0) {
         header('Content-type: text/xml');
         echo "<response error='Software not found'>error</response>";
         return;
     }
     //Application exists. Proceed with subscription
     $app = $apps->items[0];
     unset($_GET["id"]);
     $_GET["flt"] = base64_encode("=application.id:" . $id . " id:SYSTAG_FOLLOW");
     $_GET["name"] = $app->name . " Subscription";
     $_GET["subjecttype"] = "app-entry";
     $_GET["delivery"] = "2";
     $_GET["events"] = "30";
     require_once "NewsController.php";
     $news = new NewsController($this->getRequest(), $this->getResponse(), $this->getInvokeArgs());
     $news->subscribeAction();
     return;
 }