예제 #1
0
 $Session->assert_received_crumb('userfieldgroup');
 // Check permission:
 $current_User->check_perm('users', 'edit', true);
 // load data from request
 if ($edited_UserfieldGroup->load_from_Request()) {
     // We could load data from form without errors:
     // Insert in DB:
     $DB->begin();
     // because of manual assigning ID,
     // member function Userfield::dbexists() is overloaded for proper functionality
     $q = $edited_UserfieldGroup->dbexists();
     if ($q) {
         // We have a duplicate entry:
         param_error('ufgp_ID', sprintf(T_('This user field group already exists. Do you want to <a %s>edit the existing user field group</a>?'), 'href="?ctrl=userfieldsgroups&amp;action=edit&amp;ufgp_ID=' . $q . '"'));
     } else {
         $edited_UserfieldGroup->dbinsert();
         $Messages->add(T_('New User field group created.'), 'success');
     }
     $DB->commit();
     if (empty($q)) {
         // What next?
         switch ($action) {
             case 'create_copy':
                 // Redirect so that a reload doesn't write to the DB twice:
                 header_redirect('?ctrl=userfieldsgroups&action=new&ufgp_ID=' . $edited_UserfieldGroup->ID, 303);
                 // Will EXIT
                 // We have EXITed already at this point!!
                 break;
             case 'create_new':
                 // Redirect so that a reload doesn't write to the DB twice:
                 header_redirect('?ctrl=userfieldsgroups&action=new', 303);
예제 #2
0
 /**
  * Get user field group ID by name AND Try to create new if it doesn't exist yet
  *
  * @param string Field group name
  * @return integer Field group ID
  */
 function userfield_get_group_by_name($field_group_name)
 {
     if (is_null($this->userfield_groups)) {
         // Load all user field groups in cache on first time request:
         global $DB;
         $SQL = new SQL();
         $SQL->SELECT('ufgp_ID, ufgp_name');
         $SQL->FROM('T_users__fieldgroups');
         $this->userfield_groups = $DB->get_assoc($SQL->get(), 'Load all user field groups in cache array of LDAP plugin');
         // Convert all user field group names to lowercase:
         $this->userfield_groups = array_map('utf8_strtolower', $this->userfield_groups);
     }
     // Check if requested user field group already exists in DB:
     $field_group_ID = array_search(utf8_strtolower($field_group_name), $this->userfield_groups);
     if ($field_group_ID === false) {
         // No user field group in DB, Try to create new:
         // Load UserfieldGroup class:
         load_class('users/model/_userfieldgroup.class.php', 'UserfieldGroup');
         $UserfieldGroup = new UserfieldGroup();
         $UserfieldGroup->set('name', $field_group_name);
         $UserfieldGroup->set('order', 0);
         if ($UserfieldGroup->dbinsert()) {
             // New user field group has been created
             $field_group_ID = $UserfieldGroup->ID;
             // Add new user field group in cache array:
             $this->userfield_groups[$field_group_ID] = utf8_strtolower($field_group_name);
             $this->debug_log(sprintf('New user field group "%s" has been created in system', $field_group_name));
         }
     }
     return $field_group_ID;
 }