Example #1
0
 function saveShareSet()
 {
     if (!$this->request->isLoggedIn()) {
         $this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'loginForm'));
         return;
     }
     $t_set = $this->_getSet(__CA_SET_EDIT_ACCESS__);
     $o_purifier = new HTMLPurifier();
     $ps_user = $o_purifier->purify($this->request->getParameter('user', pString));
     # --- ps_user can be list of emails separated by comma
     $va_users = explode(", ", $ps_user);
     $pn_group_id = $this->request->getParameter('group_id', pInteger);
     if (!$pn_group_id && !$ps_user) {
         $va_errors["general"] = _t("Please select a user or group");
     }
     $pn_access = $this->request->getParameter('access', pInteger);
     if (!$pn_access) {
         $va_errors["access"] = _t("Please select an access level");
     }
     if (sizeof($va_errors) == 0) {
         if ($pn_group_id) {
             $t_sets_x_user_groups = new ca_sets_x_user_groups();
             if ($t_sets_x_user_groups->load(array("set_id" => $t_set->get("set_id"), "group_id" => $pn_group_id))) {
                 $this->view->setVar("message", _t('Group already has access to the lightbox'));
                 $this->render("Form/reload_html.php");
             } else {
                 $t_sets_x_user_groups->setMode(ACCESS_WRITE);
                 $t_sets_x_user_groups->set('access', $pn_access);
                 $t_sets_x_user_groups->set('group_id', $pn_group_id);
                 $t_sets_x_user_groups->set('set_id', $t_set->get("set_id"));
                 $t_sets_x_user_groups->insert();
                 if ($t_sets_x_user_groups->numErrors()) {
                     $va_errors["general"] = join("; ", $t_sets_x_user_groups->getErrors());
                     $this->view->setVar('errors', $va_errors);
                     $this->shareSetForm();
                 } else {
                     $t_group = new ca_user_groups($pn_group_id);
                     $va_group_users = $t_group->getGroupUsers();
                     if (sizeof($va_group_users)) {
                         # --- send email to each group user
                         # --- send email confirmation
                         $o_view = new View($this->request, array($this->request->getViewsDirectoryPath()));
                         $o_view->setVar("set", $t_set->getLabelForDisplay());
                         $o_view->setVar("from_name", trim($this->request->user->get("fname") . " " . $this->request->user->get("lname")));
                         # -- generate email subject line from template
                         $vs_subject_line = $o_view->render("mailTemplates/share_set_notification_subject.tpl");
                         # -- generate mail text from template - get both the text and the html versions
                         $vs_mail_message_text = $o_view->render("mailTemplates/share_set_notification.tpl");
                         $vs_mail_message_html = $o_view->render("mailTemplates/share_set_notification_html.tpl");
                         foreach ($va_group_users as $va_user_info) {
                             # --- don't send notification to self
                             if ($this->request->user->get("user_id") != $va_user_info["user_id"]) {
                                 caSendmail($va_user_info["email"], array($this->request->user->get("email") => trim($this->request->user->get("fname") . " " . $this->request->user->get("lname"))), $vs_subject_line, $vs_mail_message_text, $vs_mail_message_html);
                             }
                         }
                     }
                     $this->view->setVar("message", _t('Shared lightbox with group'));
                     $this->render("Form/reload_html.php");
                 }
             }
         } else {
             $va_error_emails = array();
             $va_success_emails = array();
             $va_error_emails_has_access = array();
             $t_user = new ca_users();
             foreach ($va_users as $vs_user) {
                 # --- lookup the user/users
                 $t_user->load(array("email" => $vs_user));
                 if ($vn_user_id = $t_user->get("user_id")) {
                     $t_sets_x_users = new ca_sets_x_users();
                     if ($vn_user_id == $t_set->get("user_id") || $t_sets_x_users->load(array("set_id" => $t_set->get("set_id"), "user_id" => $vn_user_id))) {
                         $va_error_emails_has_access[] = $vs_user;
                     } else {
                         $t_sets_x_users->setMode(ACCESS_WRITE);
                         $t_sets_x_users->set('access', $pn_access);
                         $t_sets_x_users->set('user_id', $vn_user_id);
                         $t_sets_x_users->set('set_id', $t_set->get("set_id"));
                         $t_sets_x_users->insert();
                         if ($t_sets_x_users->numErrors()) {
                             $va_errors["general"] = _t("There were errors while sharing this lightbox with %1", $vs_user) . join("; ", $t_sets_x_users->getErrors());
                             $this->view->setVar('errors', $va_errors);
                             $this->shareSetForm();
                         } else {
                             $va_success_emails[] = $vs_user;
                             $va_success_emails_info[] = array("email" => $vs_user, "name" => trim($t_user->get("fname") . " " . $t_user->get("lname")));
                         }
                     }
                 } else {
                     $va_error_emails[] = $vs_user;
                 }
             }
             if (sizeof($va_error_emails) || sizeof($va_error_emails_has_access)) {
                 $va_user_errors = array();
                 if (sizeof($va_error_emails)) {
                     $va_user_errors[] = _t("The following email(s) you entered do not belong to a registered user: "******", ", $va_error_emails));
                 }
                 if (sizeof($va_error_emails_has_access)) {
                     $va_user_errors[] = _t("The following email(s) you entered already have access to this lightbox: " . implode(", ", $va_error_emails_has_access));
                 }
                 if (sizeof($va_success_emails)) {
                     $this->view->setVar('message', _t('Shared lightbox with: ' . implode(", ", $va_success_emails)));
                 }
                 $va_errors["user"] = implode("<br/>", $va_user_errors);
                 $this->view->setVar('errors', $va_errors);
                 $this->shareSetForm();
             } else {
                 $this->view->setVar("message", _t('Shared lightbox with: ' . implode(", ", $va_success_emails)));
                 $this->render("Form/reload_html.php");
             }
             if (is_array($va_success_emails_info) && sizeof($va_success_emails_info)) {
                 # --- send email to user
                 # --- send email confirmation
                 $o_view = new View($this->request, array($this->request->getViewsDirectoryPath()));
                 $o_view->setVar("set", $t_set->getLabelForDisplay());
                 $o_view->setVar("from_name", trim($this->request->user->get("fname") . " " . $this->request->user->get("lname")));
                 # -- generate email subject line from template
                 $vs_subject_line = $o_view->render("mailTemplates/share_set_notification_subject.tpl");
                 # -- generate mail text from template - get both the text and the html versions
                 $vs_mail_message_text = $o_view->render("mailTemplates/share_set_notification.tpl");
                 $vs_mail_message_html = $o_view->render("mailTemplates/share_set_notification_html.tpl");
                 foreach ($va_success_emails as $vs_email) {
                     caSendmail($vs_email, array($this->request->user->get("email") => trim($this->request->user->get("fname") . " " . $this->request->user->get("lname"))), $vs_subject_line, $vs_mail_message_text, $vs_mail_message_html);
                 }
             }
         }
     } else {
         $this->view->setVar('errors', $va_errors);
         $this->shareSetForm();
     }
 }
<div id="caFormOverlay"><div class="pull-right pointer" onclick="caMediaPanel.hidePanel(); return false;"><span class="glyphicon glyphicon-remove-circle"></span></div>
<H1><?php 
print _t("Your User Groups");
?>
</H1>
<?php 
if (sizeof($va_user_groups)) {
    foreach ($va_user_groups as $va_user_group) {
        $t_user_group->load($va_user_group["group_id"]);
        print "<div><a href='#' onClick='\$(\"#userGroup" . $va_user_group["group_id"] . "\").slideToggle();'><div class='pull-right'><span class='glyphicon glyphicon-expand'></span></div>" . $va_user_group["name"] . "</a></div>";
        print "<div id='userGroup" . $va_user_group["group_id"] . "' style='display:none; padding-left:20px;'>";
        print '<dl>';
        if ($va_user_group["description"]) {
            print "<dt>" . _t("Description") . "</dt><dd>" . $va_user_group["description"] . "</dd>";
        }
        print "<dt>" . _t("Url to join group") . "</dt><dd>" . $this->request->config->get('site_hostname') . caNavUrl($this->request, "", "LoginReg", "joinGroup", array("group_id" => $va_user_group["group_id"])) . "</dd>";
        $va_group_users = $t_user_group->getGroupUsers();
        print "<dt>" . _t("Users") . "</dt><dd>";
        if (is_array($va_group_users) && sizeof($va_group_users)) {
            foreach ($va_group_users as $va_group_user) {
                print trim($va_group_user["fname"] . " " . $va_group_user["lname"]) . ", <a href='mailto:" . $va_group_user["email"] . "'>" . $va_group_user["email"] . "</a><br/>";
            }
        } else {
            print _t("Group has no users");
        }
        print "</dd></dl>";
        print "</div><!-- end userGroup -->";
    }
} else {
    print _t("You have made no user groups");
}