public function getResearcher() { if ($this->_researcher === null) { $Researchers = new Default_Model_Researchers(); $Researchers->filter->id->equals($this->getResearcherID()); if ($Researchers->count() > 0) { $this->_researcher = $Researchers->items[0]; } } return $this->_researcher; }
public function getHiddenBy() { if ($this->_hiddenBy === null) { $Researchers = new Default_Model_Researchers(); $Researchers->filter->id->equals($this->getHiddenByID()); if ($Researchers->count() > 0) { $this->_hiddenBy = $Researchers->items[0]; } } return $this->_hiddenBy; }
public static function sendSubscriptionVerificationTextMail($subscription) { $actions = array(); $delivery = array(); $users = new Default_Model_Researchers(); $subject = "EGI AppDB: Email subscription verification"; $body = ""; $nl = "\r\n"; $t = "\t"; //Find subscriber in researchers $users->filter->id->equals($subscription->researcherid); $users->refresh(); if (count($users->items) == 0) { error_log("[appdb:Subscription Verification Email] : Could not find user with id = " . $subscription->researcherID . " . Delivery cancelled."); return; } $user = $users->items[0]; //Get event types of subscriptions if (NewsEventType::has($subscription->events, NewsEventType::E_INSERT) == true) { $actions[] = "new software"; } if (NewsEventType::has($subscription->events, NewsEventType::E_UPDATE) == true) { $actions[] = "software updates"; } if (NewsEventType::has($subscription->events, NewsEventType::E_INSERT_CONTACT) == true) { $actions[] = "new contacts"; } if (NewsEventType::has($subscription->events, NewsEventType::E_INSERT_COMMENT) == true) { $actions[] = "new comments"; } //Get delivery types of subscriptions if (NewsDeliveryType::has($subscription->delivery, NewsDeliveryType::D_DAILY_DIGEST) == true) { $delivery[] = "daily"; } if (NewsDeliveryType::has($subscription->delivery, NewsDeliveryType::D_WEEKLY_DIGEST) == true) { $delivery[] = "every monday"; } if (NewsDeliveryType::has($subscription->delivery, NewsDeliveryType::D_MONTHLY_DIGEST) == true) { $delivery[] = "every 1st day of the month"; } $body = "Dear " . $user->firstName . " " . $user->lastName . "," . $nl . $nl; $body .= "Your request to receive e-mail notifications about '" . $subscription->name . "' has been processed. " . $nl . $nl; //Render actions (events) $body .= "You will be notified for"; if (count($actions) == 1) { $body .= " " . $actions[0]; } else { $ac = count($actions); for ($i = 0; $i < $ac; $i += 1) { $body .= " " . $actions[$i]; if ($i == $ac - 2) { $body .= ($ac > 2 ? "," : "") . " and"; } else { if ($i < $ac - 1) { $body .= ","; } } } } $body .= "." . $nl; //Render delivery $body .= "The delivery of notifications will take place"; if (count($delivery) == 1) { $body .= " " . $delivery[0]; } else { $dc = count($delivery); for ($i = 0; $i < $dc; $i += 1) { $body .= " " . $delivery[$i]; if ($i == $dc - 2) { $body .= ($dc > 2 ? "," : "") . " and"; } else { if ($i < $dc - 1) { $body .= ","; } } } } $body .= "." . $nl . $nl; $body .= 'If no new software registrations (or updates of existing software) occur within the given delivery time span, no e-mail will be sent.' . $nl . $nl; $body .= "Sincerely," . $nl; $body .= "EGI AppDB notifications service" . $nl; $body .= "website: http://" . $_SERVER["APPLICATION_UI_HOSTNAME"] . "/"; //Get primary e-mail contact of subscriber and send e-mail $rs = new Default_Model_Contacts(); $rs->filter->researcherid->equals($subscription->researcherid)->and($rs->filter->contacttypeid->equals(7))->and($rs->filter->isprimary->equals(true)); if (count($rs->refresh()->items) > 0) { $to = $rs->items[0]->data; //sendMultipartMail($subject, $to, $body,'', '*****@*****.**', 'enadyskolopassword'); EmailService::sendReport($subject, $to, $body); error_log("[appdb:Subscription Verification Email]: Sending subscription verification to " . $to); } else { error_log("[appdb:Subscription Verification Email]: Cannot find a primary e-mail for user with id = " . $subscription->researcherid); } }
public function updateallAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); return; $ldap = ApplicationConfiguration::service('egi.ldap.host'); $ldapbind = false; $ds = ldap_connect($ldap); if (ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)) { if (ldap_set_option($ds, LDAP_OPT_REFERRALS, 0)) { $ldapbind = @ldap_bind($ds, ApplicationConfiguration::service('egi.ldap.username'), ApplicationConfiguration::service('egi.ldap.password')); } } if ($ldapbind) { $users = new Default_Model_Researchers(); $users->refresh(); for ($i = 0; $i < $users->count(); $i++) { $u = $users->items[$i]; if (!isnull($u->username)) { $sr = ldap_search($ds, "ou=people,dc=egi,dc=eu", "(uid=" . $u->username . ")"); $info = ldap_get_entries($ds, $sr); if ($info["count"] > 0) { if (array_key_exists('destinationindicator', $info[0])) { $gender = $info[0]['destinationindicator'][0]; $u->gender = $gender; $u->save(); } } } } ldap_close($ds); } }
public static function sendPermissionsRequest($userid, $apikeyid, $msg) { //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"; } //Check if e-mail has value $useremail = $contacts->items[0]->data; if (trim($useremail) == '') { return "Sender has no valid primary e-mail set"; } //Get api key $apikeys = new Default_Model_APIKeys(); $apikeys->filter->id->equals($apikeyid)->and($apikeys->filter->ownerid->equals($userid)); if (count($apikeys) == 0) { return "Api key not found"; } $apikey = $apikeys->items[0]; //Get Appdb administrators $recipients = array(); $admins = new Default_Model_Researchers(); $agmf = new Default_Model_ActorGroupMembersFilter(); $agmf->groupid->numequals(-1); // admins $admins->filter->chain($agmf, "AND"); if (count($admins->items) == 0) { return ""; } //Get admins primary emails $admins = $admins->items; foreach ($admins as $admin) { $contacts = new Default_Model_Contacts(); $contacts->filter->isprimary->equals(true)->and($contacts->filter->researcherid->equals($admin->id))->and($contacts->filter->contacttypeid->equals(7)); if (count($contacts->items) == 0) { continue; } if (trim($contacts->items[0]->data) !== '') { $recipients[] = $contacts->items[0]->data; } } $recipients = array_unique($recipients); if (count($recipients) == 0) { return ""; } $textbody = self::getMailBody($user, $apikey, $msg); //Get text body and also set html body $body = preg_replace("/\\</", "<", $textbody); $body = preg_replace("/\\>/", ">", $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"] . "?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("/\\[2\\]/", "<b>" . $apikey->key . "</b>", $body); $body = "<html><head></head><body>" . $body . "</body></html>"; $textbody = preg_replace("/\t/", " ", $textbody); $textbody = preg_replace("/\\[1\\]/", $user->firstname . " " . $user->lastname . " [id: " . $user->id . ", url: http://" . $_SERVER["APPLICATION_UI_HOSTNAME"] . "?p=" . base64_encode("/people/details?id=" . $user->id) . "]", $textbody); $textbody = preg_replace("/\\[2\\]/", $apikey->key, $textbody); $subject = "EGI AppDB: API Permissions request from user " . $user->firstname . " " . $user->lastname; //sendMultipartMail($subject,$recipients, $textbody, $body, '*****@*****.**', 'enadyskolopassword',$useremail); EmailService::sendReport($subject, $recipients, $textbody, $body, $useremail); return true; }
public function getSubmission() { if ($this->_submission === null) { $Researchers = new Default_Model_Researchers(); $Researchers->filter->id->equals($this->getSubmissionID()); if ($Researchers->count() > 0) { $this->_submission = $Researchers->items[0]; } } return $this->_submission; }
/** * @overrides get() from RestResource */ public function get() { if (parent::get() !== false) { $users = new Default_Model_Researchers(); $username = $this->getParam("username"); // if ( $username != '' ) { // $users->filter->username->equals($username); // } else { // $users->filter->id->equals($this->getParam("userid")); // } $users->filter->id->equals($this->_userid); $users->refresh("xml"); if (count($users->items) > 0) { return new XMLFragmentRestResponse($users->items[0]); } else { // this should never happen, the call should have failed the // authentication $this->setError(RestErrorEnum::RE_ITEM_NOT_FOUND); return false; } } else { return false; } }
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("/\\</", "<", $textbody); $body = preg_replace("/\\>/", ">", $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 updateAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $hasEditRights = false; $entries = new Default_Model_Researchers(); if ($this->session->userid !== null) { // there is a user logged in $users = new Default_Model_Researchers(); $users->filter->id->equals($this->session->userid); $user = $users->items[0]; if ($_POST['id'] == '') { // logged in user registering another user (e.g. a manager registering someone else) if (userIsAdminOrManager($this->session->userid)) { $entry = new Default_Model_Researcher(); //prepare new entry $entry->dateInclusion = date("Y-m-d"); $entry->addedBy = $this->session->userid; $hasEditRights = true; } else { $hasEditRights = false; } // logged in user has no permission to register other users } else { $entry = $entries->item($_POST['id']); // this is an update, get existing data $hasEditRights = $user->privs->canEditPersonProfile($entry); } } else { if ($this->session->username !== null) { // no user logged in, but new user registering own self $entry = new Default_Model_Researcher(); //prepare new entry $entry->dateInclusion = date("Y-m-d"); $entry->username = $this->session->username; $entry->lastLogin = time(); $entry->password = $this->session->claimPassword; setAuthCookies($this->session->username, $this->session->claimPassword); $this->session->claimPassword = null; $hasEditRights = true; } } if ($hasEditRights) { $entry->lastName = $_POST['lastName']; $entry->firstName = $_POST['firstName']; $entry->gender = $_POST['gender']; $entry->institution = $_POST['institution']; $oldCountryID = $entry->countryID; $entry->countryID = $_POST['countryID']; $oldRoleID = $entry->positionTypeID; $entry->positionTypeID = $_POST['positionTypeID']; if ($_POST['newimage'] !== "") { $imgfile = APPLICATION_PATH . "/../public/" . $_POST['newimage']; if (file_exists(APPLICATION_PATH . "/../cache/ppl-image-" . $entry->id . ".png")) { unlink(APPLICATION_PATH . "/../cache/ppl-image-" . $entry->id . ".png"); } $entry->image = pg_escape_bytea(base64_encode(file_get_contents($imgfile))); } if ($this->session->userid === null) { $entries->add($entry); $this->session->userid = $entry->id; $this->session->user = $entry; $this->session->fullname = $entry->firstname . " " . $entry->lastname; } else { if ($_POST['id'] == '') { $entries->add($entry); $this->session->lastPplID = $entry->id; } else { $entry->save(); } } $entries->filter->id->equals($entry->id); $found_new_entry = false; $search_new_entry_count = 0; while (!$found_new_entry || $search_new_entry_count > 10) { $entries->refresh(); $found_new_entry = count($entries->items) > 0; if (!$found_new_entry) { sleep(1); } $search_new_entry_count = $search_new_entry_count + 1; } if (!$found_new_entry) { error_log("Could not find new user entry in DB after 10 tries... This should not happen (userid: " . $entry->id . ")"); return; } $entry = $entries->items[0]; $ant = 'his/her'; if (!isnull($entry->gender)) { if ($entry->gender == 'male') { $ant = 'his'; } if ($entry->gender == 'female') { $ant = 'her'; } } $conts = new Default_Model_Contacts(); $conts->refresh(); for ($i = count($entry->contacts) - 1; $i >= 0; $i--) { $conts->remove($entry->contacts[$i]); } foreach ($_POST as $key => $value) { if (substr($key, 0, 7) === "contact" && substr($key, 0, 11) !== "contactType") { $cnum = substr($key, 7); $cont = new Default_Model_Contact(); $cont->researcherID = $entry->id; $cont->data = $value; $cont->contactTypeID = $_POST['contactType' . $cnum]; $conts->add($cont); } } } if ($entry && ($this->session->userid == null || $this->session->userid == $entry->id)) { $this->session->userid = $entry->id; //Reload session data in case of claim or save new account $ppl = new Default_Model_Researchers(); $ppl->filter->id->equals($this->session->userid); $user = $ppl->items[0]; $this->session->user = $user; $this->session->fullname = $user->firstname . " " . $user->lastname; $this->session->userRole = $user->positionTypeID; $this->session->userCountryID = $user->countryID; $this->session->userCountryName = $user->country->name; $this->session->cname = $user->cname; } }
public function getLastupdatedby() { if ($this->_lastupdatedby === null) { $Researchers = new Default_Model_Researchers(); $Researchers->filter->id->equals($this->getLastupdatedbyID()); if ($Researchers->count() > 0) { $this->_lastupdatedby = $Researchers->items[0]; } } return $this->_lastupdatedby; }
public function ppldetailsAction() { $pplID = $this->_getParam("id"); trackPage('/people/details?id=' . $pplID, $this->_getParam("format")); if ($pplID == '') { $pplID = $this->session->lastPplID; } $this->_helper->layout->disableLayout(); $apps = new Default_Model_Researchers(); if ($this->_getParam("id") == "0") { $this->view->entry = new Default_Model_Researcher(); $this->view->entry->countryID = '0'; } else { $apps->filter->id->equals($pplID); $apps->refresh($this->_getParam('format'), true, $this->_getParam('userid')); $this->view->entry = $apps->items[0]; $this->showimageAction(); } $this->view->dialogCount = $_GET['dc']; $this->view->positionTypes = new Default_Model_PositionTypes(); $this->view->positionTypes->filter->orderBy('ord'); $this->view->countries = new Default_Model_Countries(); $this->view->countries->filter->orderBy('name'); $this->view->contactTypes = new Default_Model_ContactTypes(); $this->view->session = $this->session; if ($this->session->username !== null && $this->session->userid !== null) { $users = new Default_Model_Researchers(); $users->filter->id->equals($this->session->userid); $this->view->user = $users->items[0]; } else { $this->view->user = null; } }