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;
 }
 /**
  *
  */
 private function _setUniqueSetCode()
 {
     if (!$this->getPrimaryKey()) {
         return null;
     }
     if (!strlen(trim($this->get('form_code')))) {
         $this->setMode(ACCESS_WRITE);
         if (!($vs_label = $this->getLabelForDisplay())) {
             $vs_label = 'form_' . $this->getPrimaryKey();
         }
         $vs_new_form_name = substr(preg_replace('![^A-Za-z0-9]+!', '_', $vs_label), 0, 50);
         if (ca_search_forms::find(array('form_code' => $vs_new_form_name), array('returnAs' => 'firstId')) > 0) {
             $vs_new_form_name .= '_' . $this->getPrimaryKey();
         }
         $this->set('form_code', $vs_new_form_name);
         return $this->update();
     }
     return false;
 }