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 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; } }
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; }