Example #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;
 }
Example #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;
     }
 }
 private function getGroupObject($pb_set_view_vars = true, $pn_group_id = null)
 {
     if (!($t_group = $this->pt_group)) {
         if (!($vn_group_id = $this->request->getParameter('group_id', pInteger))) {
             $vn_group_id = $pn_group_id;
         }
         $t_group = new ca_user_groups($vn_group_id);
     }
     // Check if user actually owns the specified object
     if ($t_group->getPrimaryKey() && $t_group->get('user_id') != $this->request->user->getUserID()) {
         return false;
     }
     if ($pb_set_view_vars) {
         $this->view->setVar('group_id', $vn_group_id);
         $this->view->setVar('t_group', $t_group);
     }
     $this->pt_group = $t_group;
     return $t_group;
 }