Esempio n. 1
0
 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);
     }
 }
Esempio n. 2
0
 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);
     }
 }
Esempio n. 3
0
 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;
     }
 }
Esempio n. 4
0
 /**
  * @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 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;
     }
 }