public function getApplication()
 {
     if ($this->_application === null) {
         $Applications = new Default_Model_Applications();
         $Applications->filter->id->equals($this->getAppID());
         if ($Applications->count() > 0) {
             $this->_application = $Applications->items[0];
         }
     }
     return $this->_application;
 }
Exemple #2
0
 public function applications()
 {
     $rs = $this->_db->query("SELECT id FROM applications WHERE guid IN (SELECT object FROM permissions WHERE actor = '" . $this->_actor->guid . "');")->fetchAll();
     $ids = array();
     foreach ($rs as $row) {
         $ids[] = $row['id'];
     }
     if (count($ids) > 0) {
         $apps = new Default_Model_Applications();
         $apps->filter->orderBy('name');
         $apps->filter->id->in($ids);
         return $apps->refresh();
     } else {
         return null;
     }
 }
Exemple #3
0
 public static function sendMessage($appid, $userid, $recipientid, $message)
 {
     //Get sender
     $users = new Default_Model_Researchers();
     $users->filter->id->equals($userid);
     if ($users->count() == 0) {
         return "Sender not found";
     }
     $user = $users->items[0];
     //Get sender's primary email
     $contacts = new Default_Model_Contacts();
     $contacts->filter->isprimary->equals(true)->and($contacts->filter->researcherid->equals($userid));
     if ($contacts->count() == 0) {
         return "Sender has no primary e-mail set";
     }
     $useremail = $contacts->items[0]->data;
     //Get recipient
     $recipients = new Default_Model_Researchers();
     $recipients->filter->id->equals($recipientid);
     if ($recipients->count() == 0) {
         return "Recipient not found";
     }
     $recipient = $recipients->items[0];
     //Get recipient's primary email
     $contacts = new Default_Model_Contacts();
     $contacts->filter->isprimary->equals(true)->and($contacts->filter->researcherid->equals($recipientid));
     if ($contacts->count() == 0) {
         return "Recipient has no primary e-mail set";
     }
     $recipientmail = $contacts->items[0]->data;
     //Get application
     $applications = new Default_Model_Applications();
     $applications->filter->id->equals($appid);
     if ($applications->count() == 0) {
         return "Software not found";
     }
     $app = $applications->items[0];
     //Decode message
     $message = base64_decode($message);
     if (strlen(trim($message)) === 0) {
         return "Message is empty";
     }
     //Get text body and also set html body
     $textbody = self::getTextBody($app, $user, $useremail, $recipient, $message);
     $body = preg_replace("/\\</", "&lt;", $textbody);
     $body = preg_replace("/\\>/", "&gt;", $body);
     $body = preg_replace("/\n/", "<br/>", $body);
     $body = preg_replace("/\t/", "<span style='padding-left:10px;'></span>", $body);
     $body = preg_replace("/\\[1\\]/", "<a href='http://" . $_SERVER["APPLICATION_UI_HOSTNAME"] . "' target='_blank' title='Visit EGI Applications Database' >EGI AppDB</a>", $body);
     $body = preg_replace("/\\[2\\]/", "<a href='http://" . $_SERVER["APPLICATION_UI_HOSTNAME"] . "?p=" . base64_encode("//people/details?id=" . $user->id) . "' target='_blank' title='View person's entry in EGI AppDB' >" . $user->firstname . " " . $user->lastname . "</a>", $body);
     $body = preg_replace("/\\[3\\]/", "'<a href='http://" . $_SERVER["APPLICATION_UI_HOSTNAME"] . "?p=" . base64_encode("/apps/details?id=" . $app->id) . "' target='_blank' title='View software entry in EGI AppDB' >" . $app->name . "</a>'", $body);
     $body = "<html><head></head><body>" . $body . "</body></html>";
     $textbody = preg_replace("/\t/", "   ", $textbody);
     $textbody = preg_replace("/\\[1\\]/", "EGI AppDB [1]", $textbody);
     $textbody = preg_replace("/\\[2\\]/", $user->firstname . " " . $user->lastname . " [2]", $textbody);
     $textbody = preg_replace("/\\[3\\]/", "'" . $app->name . "' [3]", $textbody);
     $textbody .= "\n\n________________________________________________________________________________________________________\n";
     $textbody .= "[1]. http://" . $_SERVER["APPLICATION_UI_HOSTNAME"] . "\n";
     $textbody .= "[2]. http://" . $_SERVER["APPLICATION_UI_HOSTNAME"] . "?p=" . base64_encode("/people/details?id=" . $user->id) . "\n";
     $textbody .= "[3]. http://" . $_SERVER["APPLICATION_UI_HOSTNAME"] . "?p=" . base64_encode("/apps/details?id=" . $app->id) . " \n";
     $subject = "EGI Applications Database: " . $user->firstname . " " . $user->lastname . " sent you a message";
     if (trim($useremail) === '') {
         $useremail = false;
     }
     //sendMultipartMail($subject,$recipientmail, $textbody, $body, '*****@*****.**', 'enadyskolopassword',$useremail, null, false, array("From"=>$useremail));
     EmailService::sendReportAsUser($useremail, $subject, $recipientmail, $textbody, $body);
 }
 public function tagsAction()
 {
     $this->_helper->layout->disableLayout();
     $uid = $this->session->userid;
     $urole = $this->session->userRole;
     $action = isset($_GET["action"]) ? strtolower($_GET["action"]) : '';
     $appid = isset($_GET["id"]) ? $_GET["id"] : -1;
     $tag = isset($_GET["tag"]) ? trim($_GET["tag"]) : '';
     $tag = urldecode($tag);
     $tag = str_replace(" ", ".", $tag);
     if ($appid === -1) {
         $this->view->Error = "no appid given";
         return;
     }
     if ($tag === '' && $action !== '') {
         $this->view->Error = "no tag given";
         return;
     }
     if ($action === "add" || $action === "remove") {
         if (is_null($uid)) {
             $this->view->Error = "not logged in";
             return;
         }
         $apptags = new Default_Model_AppTags();
         $flt1 = $apptags->filter;
         $flt1->appid->equals($appid)->and($flt1->tag->ilike($tag));
         if (count($apptags->items) > 0) {
             if ($action === "remove") {
                 if ($apptags->items[0]->researcherid !== $uid) {
                     $isOwner = false;
                     $isAdmin = false;
                     $apps = new Default_Model_Applications();
                     $apps->filter->appid->equals($appid);
                     //Check if current user is the owner of the applicaiton entry
                     if (count($apps->items) > 0) {
                         if ($apps->items[0]->addedBy === $uid || $apps->items[0]->ownerid === $uid) {
                             $isOwner = true;
                         }
                     }
                     //Check if current user role is administrator or manager
                     if (userIsAdminOrManager($uid)) {
                         $isAdmin = true;
                     }
                     if (!($isOwner || $isAdmin)) {
                         //check if the current user is the submitter of the tag
                         $apptags = new Default_Model_AppTags();
                         $flt1 = $apptags->filter;
                         $flt1->appid->equals($appid)->and($flt1->tag->ilike($tag))->and($flt1->researcherid->equals($uid));
                         $apptagsitems = $apptags->items;
                         if (count($apptagsitems) == 0) {
                             $this->view->Error = 'permission denied';
                             return;
                         }
                     }
                 }
             }
         }
     } else {
         if ($tag != '') {
             $this->view->Error = "No action given";
             return;
         }
     }
     $p = new Default_Model_Permissions();
     $p->filter->researcherid->equals($this->session->userid)->and($p->filter->actionid->equals(24));
     $pc = $p->count();
     if ($pc === 0) {
         $this->view->Error = "The user is not allowed to change tags";
         return;
     }
     global $application;
     $db = $application->getBootstrap()->getResource('db');
     $db->setFetchMode(Zend_Db::FETCH_OBJ);
     try {
         if ($action === "add") {
             $t = substr($tag, 0, 1);
             if (preg_match("/[A-Za-z]/", $t) <= 0) {
                 $this->view->Error = "Tags must start with a text character.";
                 return;
             }
             if (preg_match("/[\\>\\<\\=\\!]/", $tag) > 0) {
                 $this->view->Error = "Tag contains invalid characters (> < = !)";
                 return;
             }
             if (strlen($tag) > 50) {
                 $this->view->Error = "Tags must be less than 50 characters long.";
                 return;
             }
             $tags = new Default_Model_AppTags();
             $tags->filter->appid->equals($appid)->and($tags->filter->tag->ilike($tag));
             if ($tags->count() == 0) {
                 $t = new Default_Model_AppTag();
                 $t->appid = $appid;
                 $t->tag = $tag;
                 $t->researcherid = $uid;
                 $tags->add($t);
             }
         } else {
             if ($action === "remove") {
                 $tags = new Default_Model_AppTags();
                 $tags->filter->appid->equals($appid)->and($tags->filter->tag->ilike($tag));
                 $tags->refresh();
                 if ($tags->count() > 0) {
                     $tags->remove($tags->items[0]);
                 }
             } else {
                 $apps = new Default_Model_Applications();
                 $apps->filter->id->equals($appid);
                 $c = $apps->count();
                 if ($c > 0) {
                     $apps->refresh();
                     $kws = $apps->items[0]->keywords;
                     $kws = is_array($kws) ? implode(",", $kws) : $kws;
                     $kws = str_replace(array("{", "}", "\""), "", $kws);
                     $this->view->Response = $kws;
                     $this->view->total = $apps->count();
                     return;
                 } else {
                     $this->view->Error = "Could not find the software";
                 }
             }
         }
     } catch (Exception $e) {
         $this->view->Error = simpleHTML2Text($e->getMessage());
         return;
     }
     $this->view->Response = "OK";
 }
 public function __construct($appid)
 {
     parent::__construct();
     $this->_appid = $appid;
     $this->filter = null;
 }
Exemple #6
0
 /**
  * @overrides put() from RestResource
  */
 public function put()
 {
     if (parent::put() !== false) {
         $bm = new Default_Model_AppBookmark();
         $id = $this->_parser->getID($this->getData(), "application:application");
         if ($this->_parser->getError() === RestErrorEnum::RE_OK) {
             $apps = new Default_Model_Applications();
             $apps->filter->id->equals($id);
             if ($apps->count() > 0) {
                 $bm->appid = $id;
                 $bm->researcherid = $this->getParam("id");
                 try {
                     $bm->save();
                 } catch (Exception $e) {
                     $this->setError(RestErrorEnum::RE_BACKEND_ERROR, $e->getMessage());
                     return false;
                 }
                 $res = new RestAppItem(array("id" => $id), $this);
                 return $res->get();
             } else {
                 $this->setError(RestErrorEnum::RE_ITEM_NOT_FOUND);
                 return false;
             }
         } else {
             $this->setError($this->_parser->getError());
             return false;
         }
     } else {
         return false;
     }
 }
 public function appdetailsAction()
 {
     $this->_helper->layout->disableLayout();
     $appID = $this->_getParam("id");
     $format = $this->_getParam("format");
     if ($format === "json") {
         $format = "xml";
     }
     trackPage('/apps/details/' . $appID, $format);
     if ($appID == '') {
         $appID = $this->session->lastAppID;
     }
     if ($appID == "0") {
         $this->view->entry = new Default_Model_Application();
         $this->view->entry->name = 'New Application/Tool';
         $this->view->entry->description = '';
         $this->view->entryid = 0;
     } else {
         if ($format === "xml") {
             $apps = new Default_Model_Applications();
             $apps->filter->id->equals($appID);
             $apps->refresh($format, true);
             if ($apps->count() > 0) {
                 $this->view->entry = $apps->items[0];
             }
         } else {
             $this->view->entry = null;
             //$app;
             $this->view->entryid = $appID;
         }
     }
     $this->view->dialogCount = $_GET['dc'];
     if ($this->session->username !== null) {
     } else {
         $this->view->user = null;
     }
     $this->view->session = $this->session;
 }