Beispiel #1
0
 public function processSearchForms()
 {
     require_once __CA_MODELS_DIR__ . "/ca_search_forms.php";
     require_once __CA_MODELS_DIR__ . "/ca_search_form_placements.php";
     $o_config = Configuration::load();
     $vo_dm = Datamodel::load();
     if ($this->ops_base_name) {
         // "merge" profile and its base
         $va_forms = array();
         if ($this->opo_base->searchForms) {
             foreach ($this->opo_base->searchForms->children() as $vo_form) {
                 $va_forms[self::getAttribute($vo_form, "code")] = $vo_form;
             }
         }
         if ($this->opo_profile->searchForms) {
             foreach ($this->opo_profile->searchForms->children() as $vo_form) {
                 $va_forms[self::getAttribute($vo_form, "code")] = $vo_form;
             }
         }
     } else {
         if ($this->opo_profile->searchForms) {
             foreach ($this->opo_profile->searchForms->children() as $vo_form) {
                 $va_forms[self::getAttribute($vo_form, "code")] = $vo_form;
             }
         }
     }
     if (!is_array($va_forms) || sizeof($va_forms) == 0) {
         return true;
     }
     foreach ($va_forms as $vo_form) {
         $vs_form_code = self::getAttribute($vo_form, "code");
         $vb_system = self::getAttribute($vo_form, "system");
         $vs_table = self::getAttribute($vo_form, "type");
         if (!($t_instance = $vo_dm->getInstanceByTableName($vs_table, true))) {
             continue;
         }
         if (method_exists($t_instance, 'getTypeList') && !sizeof($t_instance->getTypeList())) {
             continue;
         }
         // no types configured
         if ($o_config->get($vs_table . '_disable')) {
             continue;
         }
         $vn_table_num = (int) $vo_dm->getTableNum($vs_table);
         $t_form = $this->opb_updating ? ca_search_forms::find(array('form_code' => (string) $vs_form_code, 'table_num' => $vn_table_num), array('returnAs' => 'firstModelInstance')) : false;
         $t_form = $t_form ? $t_form : new ca_search_forms();
         $t_form->setMode(ACCESS_WRITE);
         $t_form->set("form_code", (string) $vs_form_code);
         $t_form->set("is_system", (int) $vb_system);
         $t_form->set("table_num", $vn_table_num);
         $va_settings = $this->_processSettings($t_form, $vo_form->settings);
         if ($t_form->getPrimaryKey()) {
             $t_form->update();
         } else {
             $t_form->set("user_id", 1);
             // let administrative user own these
             $t_form->insert();
         }
         if ($t_form->numErrors()) {
             $this->addError("There was an error while inserting search form {$vs_form_code}: " . join(" ", $t_form->getErrors()));
         } else {
             self::addLabelsFromXMLElement($t_form, $vo_form->labels, $this->opa_locales);
             if ($t_form->numErrors()) {
                 $this->addError("There was an error while inserting search form label for {$vs_form_code}: " . join(" ", $t_form->getErrors()));
             }
             if (!$this->processSearchFormPlacements($t_form, $vo_form->bundlePlacements, null)) {
                 return false;
             }
         }
         // set user and group access
         if ($vo_form->userAccess) {
             $t_user = new ca_users();
             $va_form_users = array();
             foreach ($vo_form->userAccess->children() as $vo_permission) {
                 $vs_user = trim((string) self::getAttribute($vo_permission, "user"));
                 $vn_access = $this->_convertUserGroupAccessStringToInt(self::getAttribute($vo_permission, 'access'));
                 if ($vn_access && $t_user->load(array('user_name' => $vs_user))) {
                     $va_form_users[$t_user->getUserID()] = $vn_access;
                 } else {
                     $this->addError("User name or access value invalid for search form {$vs_form_code} (permission item with user name '{$vs_user}')");
                 }
             }
             if (sizeof($va_form_users) > 0) {
                 $t_form->addUsers($va_form_users);
             }
         }
         if ($vo_form->groupAccess) {
             $t_group = new ca_user_groups();
             $va_form_groups = array();
             foreach ($vo_form->groupAccess->children() as $vo_permission) {
                 $vs_group = trim((string) self::getAttribute($vo_permission, "group"));
                 $vn_access = $this->_convertUserGroupAccessStringToInt(self::getAttribute($vo_permission, 'access'));
                 if ($vn_access && $t_group->load(array('code' => $vs_group))) {
                     $va_form_groups[$t_group->getPrimaryKey()] = $vn_access;
                 } else {
                     $this->addError("Group code or access value invalid for search form {$vs_form_code} (permission item with group code '{$vs_group}')");
                 }
             }
             if (sizeof($va_form_groups) > 0) {
                 $t_form->addUserGroups($va_form_groups);
             }
         }
     }
     return true;
 }
Beispiel #2
0
 /**
  * Determines whether current user is a member of the specified group.
  *
  * @access public
  * @param mixed $ps_group The group to test for the current user for membership in. Group may be specified by name, short name or id.
  * @return bool Returns true if user is a member of the group, false if not.
  */
 public function inGroup($ps_group)
 {
     if (!($pn_user_id = $this->getPrimaryKey())) {
         return false;
     }
     $vb_got_group = 0;
     $t_group = new ca_user_groups();
     if (is_numeric($ps_group)) {
         $vb_got_group = $t_group->load($ps_group);
     }
     if (!$vb_got_group) {
         if (!$t_group->load(array("name" => $ps_group))) {
             if (!$t_group->load(array("name_short" => $ps_group))) {
                 return false;
             }
         }
         $vb_got_group = 1;
     }
     if ($vb_got_group) {
         $o_db = $this->getDb();
         $qr_res = $o_db->query("\n\t\t\t\tSELECT relation_id \n\t\t\t\tFROM ca_users_x_groups\n\t\t\t\tWHERE\n\t\t\t\t\t(user_id = ?) AND\n\t\t\t\t\t(group_id = ?)\n\t\t\t", (int) $pn_user_id, (int) $t_group->getPrimaryKey());
         if ($qr_res->nextRow()) {
             return true;
         } else {
             return false;
         }
     } else {
         $this->postError(945, _t("Group '%1' does not exist", $ps_group), "User->inGroup()");
         return false;
     }
 }
 public function getGroupsAsDOM()
 {
     $t_group = new ca_user_groups();
     $vo_groups = $this->opo_dom->createElement("groups");
     $qr_groups = $this->opo_db->query("SELECT * FROM ca_user_groups WHERE parent_id IS NOT NULL");
     while ($qr_groups->nextRow()) {
         $t_group->load($qr_groups->get("group_id"));
         $vo_group = $this->opo_dom->createElement("group");
         $vo_group->setAttribute("code", $this->makeIDNO($t_group->get("code")));
         $vo_group->appendChild($this->opo_dom->createElement("name", caEscapeForXML($t_group->get("name"))));
         $vo_group->appendChild($this->opo_dom->createElement("description", caEscapeForXML($t_group->get("description"))));
         if (is_array($va_roles = $t_group->getGroupRoles())) {
             $vo_roles = $this->opo_dom->createElement("roles");
             foreach ($va_roles as $va_role) {
                 $vo_roles->appendChild($this->opo_dom->createElement("role", $this->makeIDNO($va_role["code"])));
             }
             $vo_group->appendChild($vo_roles);
         }
         $vo_groups->appendChild($vo_group);
     }
     return $vo_groups;
 }
 function joinGroup()
 {
     $t_user_group = new ca_user_groups();
     $pn_group_id = $this->request->getParameter("group_id", pInteger);
     if ($pn_group_id) {
         if ($this->request->isLoggedIn()) {
             if (!$this->request->user->inGroup($pn_group_id)) {
                 $this->request->user->addToGroups($pn_group_id);
                 $this->request->session->setVar("join_user_group_id", "");
                 $vs_group_message = _t("You were added to the group");
             } else {
                 $this->request->session->setVar("join_user_group_id", "");
                 $vs_group_message = _t("You are already a member of the group");
             }
             $this->notification->addNotification($vs_group_message, __NOTIFICATION_TYPE_INFO__);
             $this->response->setRedirect(caNavUrl($this->request, "", "Sets", "Index"));
         } else {
             $t_user_group->load($pn_group_id);
             $this->request->session->setVar("join_user_group_id", $pn_group_id);
             $this->view->setVar("message", _t("Login/Register to join \"%1\"", $t_user_group->get("name")));
             $this->loginForm();
         }
     } else {
         $this->view->setVar("message", _t("Invalid user group"));
     }
 }
Beispiel #5
0
 function saveUserGroup()
 {
     if (!$this->request->isLoggedIn()) {
         $this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'loginForm'));
         return;
     }
     global $g_ui_locale_id;
     // current locale_id for user
     $va_errors = array();
     $o_purifier = new HTMLPurifier();
     $t_user_group = new ca_user_groups();
     if ($pn_group_id = $this->request->getParameter('group_id', pInteger)) {
         $t_user_group->load($pn_group_id);
     }
     # --- check for errors
     # --- group name - required
     $ps_name = $o_purifier->purify($this->request->getParameter('name', pString));
     if (!$ps_name) {
         $va_errors["name"] = _t("Please enter the name of your user group");
     } else {
         $this->view->setVar("name", $ps_name);
     }
     # --- user group description - optional
     $ps_description = $o_purifier->purify($this->request->getParameter('description', pString));
     $this->view->setVar("description", $ps_description);
     if (sizeof($va_errors) == 0) {
         $t_user_group->setMode(ACCESS_WRITE);
         $t_user_group->set('name', $ps_name);
         $t_user_group->set('description', $ps_description);
         if ($t_user_group->get("group_id")) {
             $t_user_group->update();
         } else {
             $t_user_group->set('user_id', $this->request->getUserID());
             $t_user_group->set('code', 'lb_' . $this->request->getUserID() . '_' . time());
             $t_user_group->insert();
             if ($t_user_group->get("group_id")) {
                 $t_user_group->addUsers($this->request->getUserID());
             }
         }
         if ($t_user_group->numErrors()) {
             $va_errors["general"] = join("; ", $t_user_group->getErrors());
             $this->view->setVar('errors', $va_errors);
             $this->userGroupForm();
         } else {
             # --- add current user to group
             $this->view->setVar("message", _t('Saved user group.'));
             $this->render("Form/reload_html.php");
         }
     } else {
         $this->view->setVar('errors', $va_errors);
         $this->userGroupForm();
     }
 }
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License version 3
 *
 * ----------------------------------------------------------------------
 */
$va_user_groups = $this->getVar("user_groups");
$t_user_group = new ca_user_groups();
?>
<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");
Beispiel #7
0
         # ----------------------------------------
         case "U":
             print _t("changed an item in %1", caNavLink($this->request, $va_activity["name"], "", "", "Sets", "setDetail", array("set_id" => $va_activity["set_id"])));
             break;
             # ----------------------------------------
         # ----------------------------------------
         case "D":
             print _t("removed and item from %1", caNavLink($this->request, $va_activity["name"], "", "", "Sets", "setDetail", array("set_id" => $va_activity["set_id"])));
             break;
             # ----------------------------------------
     }
     break;
     # ----------------------------------------
 # ----------------------------------------
 case $o_dm->getTableNum("ca_sets_x_user_groups"):
     $t_group->load($va_activity["snapshot"]["group_id"]);
     switch ($va_activity["changetype"]) {
         case "I":
             print _t("shared %1 with %2", caNavLink($this->request, $va_activity["name"], "", "", "Sets", "setDetail", array("set_id" => $va_activity["set_id"])), $t_group->get("name"));
             break;
             # ----------------------------------------
         # ----------------------------------------
         case "U":
             print _t("changed how they share %1 with %2", caNavLink($this->request, $va_activity["name"], "", "", "Sets", "setDetail", array("set_id" => $va_activity["set_id"])), $t_group->get("name"));
             break;
             # ----------------------------------------
         # ----------------------------------------
         case "D":
             print _t("unshared %1 with %2", caNavLink($this->request, $va_activity["name"], "", "", "Sets", "setDetail", array("set_id" => $va_activity["set_id"])), $t_group->get("name"));
             break;
             # ----------------------------------------