/**
  * Add group to user and write to persistence immediately
  * The method has to update user's profile and group relationship
  *
  * @var CMS_profile_user $user
  * @return true on success, false on failure
  * @access public
  */
 function addToUserAndWriteToPersistence(&$user, $writeUser = true)
 {
     if (is_a($user, "CMS_profile_user") && !$user->hasError()) {
         //Get current user groups ids
         $userGroupIds = CMS_profile_usersGroupsCatalog::getGroupsOfUser($user, true, true);
         //if user has no group, we must clear his profile before
         if (!$userGroupIds) {
             //reset profile clearances
             $user->resetClearances();
         }
         // Update user profile
         $user->addPageClearances(parent::getPageClearances());
         $user->addModuleClearances(parent::getModuleClearances());
         $user->addModuleCategoriesClearancesStack(parent::getModuleCategoriesClearancesStack());
         $user->addValidationClearances(parent::getValidationClearances());
         $user->addAdminClearance(parent::getAdminClearance());
         $user->addTemplateGroupsDenied(parent::getTemplateGroupsDenied());
         $user->addRowGroupsDenied(parent::getRowGroupsDenied());
         $user->setActive(true);
         if ($writeUser) {
             $user->writeToPersistence();
         }
         if (!$user->hasError()) {
             if (!SensitiveIO::isInSet($user->getUserId(), $this->_users)) {
                 // Insert this user in group
                 $this->_users[] = $user->getUserId();
                 $sql = "\n\t\t\t\t\tinsert into\n\t\t\t\t\t\tprofileUsersByGroup\n\t\t\t\t\tset\n\t\t\t\t\t\tgroupId_gu='" . $this->_groupId . "' ,\n\t\t\t\t\t\tuserId_gu='" . $user->getUserID() . "'\n\t\t\t\t\t";
                 $q = new CMS_query($sql);
                 if ($q->hasError()) {
                     $this->raiseError('Insertion failed');
                 } else {
                     return true;
                 }
             } else {
                 return true;
             }
         } else {
             $this->raiseError('User error when adding group values');
         }
     } else {
         $this->raiseError('Incorrect user given');
     }
     return false;
 }
Beispiel #2
0
 /**
  * Writes the  user Data into persistence (MySQL for now).
  *
  * @return boolean true on success, false on failure
  * @access public
  */
 function writeToPersistence()
 {
     $this->writeProfileToPersistence();
     $this->_contactData->writeToPersistence();
     //if deleted, must set the login to nothing, so this login could be reused in the future
     if ($this->_deleted) {
         $this->_login = '';
     }
     $sql_fields = "\n\t\t\tactive_pru='" . $this->_active . "',\n\t\t\tdeleted_pru='" . $this->_deleted . "',\n\t\t\tlogin_pru='" . SensitiveIO::sanitizeSQLString($this->_login) . "',\n\t\t\tpassword_pru='" . SensitiveIO::sanitizeSQLString($this->_password) . "',\n\t\t\tfirstName_pru='" . SensitiveIO::sanitizeSQLString($this->_firstName) . "',\n\t\t\tlastName_pru='" . SensitiveIO::sanitizeSQLString($this->_lastName) . "',\n\t\t\tcontactData_pru='" . SensitiveIO::sanitizeSQLString($this->_contactData->getId()) . "',\n\t\t\tlanguage_pru='" . SensitiveIO::sanitizeSQLString($this->_language->getCode()) . "',\n\t\t\tprofile_pru='" . SensitiveIO::sanitizeSQLString(parent::getId()) . "',\n\t\t\talerts_pru='" . SensitiveIO::sanitizeSQLString($this->_alerts->getTextDefinition()) . "',\n\t\t\tfavorites_pru='" . SensitiveIO::sanitizeSQLString(implode(',', $this->_favorites)) . "'\n\t\t";
     if ($this->_userId) {
         $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tprofilesUsers\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields . "\n\t\t\t\twhere\n\t\t\t\t\tid_pru='" . $this->_userId . "'\n\t\t\t";
     } else {
         $sql = "\n\t\t\t\tinsert into\n\t\t\t\t\tprofilesUsers\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields;
     }
     $q = new CMS_query($sql);
     if ($q->hasError()) {
         return false;
     } elseif (!$this->_userId) {
         $this->_userId = $q->getLastInsertedID();
     }
     // Update validation catalog
     if ($this->_validationChange || $this->_deleted) {
         $sql = "\n\t\t\t\tdelete\n\t\t\t\tfrom\n\t\t\t\t\tprofilesUsers_validators\n\t\t\t\twhere\n\t\t\t\t\tuserId_puv='" . $this->_userId . "'\n\t\t\t\t";
         $q = new CMS_query($sql);
         if ($this->_active) {
             //loop through validationClearances
             $validationClearances = parent::getValidationClearances();
             $elements = $validationClearances->getElements();
             $sql = '';
             foreach ($elements as $value) {
                 $sql .= $sql ? ', ' : '';
                 $sql .= "('" . $this->_userId . "' ,'" . $value[0] . "') ";
             }
             if ($sql) {
                 $sql = "\n\t\t\t\t\t\t\tinsert into\n\t\t\t\t\t\t\t\tprofilesUsers_validators (userId_puv, module_puv)\n\t\t\t\t\t\t\tvalues\n\t\t\t\t\t\t\t\t" . $sql;
                 $q = new CMS_query($sql);
             }
         }
         $this->_validationChange = false;
     }
     //if deleted, must remove user from group list
     if ($this->_deleted) {
         $sql = "\n\t\t\t\tdelete\n\t\t\t\tfrom\n\t\t\t\t\tprofileUsersByGroup\n\t\t\t\twhere\n\t\t\t\t\tuserId_gu='" . $this->_userId . "'\n\t\t\t";
         $q = new CMS_query($sql);
     }
     //Clear polymod cache
     //CMS_cache::clearTypeCacheByMetas('polymod', array('resource' => 'users'));
     CMS_cache::clearTypeCache('polymod');
     return true;
 }