public function Validate($Criteria, $Form)
 {
     $Validation = new Gdn_Validation();
     $Validation->ApplyRules(array(array('Name' => 'Target', 'Validation' => array('Required', 'Integer')), array('Name' => 'Duration', 'Validation' => array('Required', 'Integer')), array('Name' => 'Period', 'Validation' => 'Required')));
     $Validation->Validate($Criteria);
     $Form->SetValidationResults($Validation->Results());
 }
Exemple #2
0
 public function Delete($RoleID = FALSE)
 {
     $this->Title(Translate('Delete Role'));
     $this->Permission('Garden.Roles.Manage');
     $this->AddSideMenu('garden/role');
     $Role = $this->RoleModel->GetByRoleID($RoleID);
     if ($Role->Deletable == '0') {
         $this->Form->AddError('You cannot delete this role.');
     }
     // Make sure the form knows which item we are deleting.
     $this->Form->AddHidden('RoleID', $RoleID);
     // Figure out how many users will be affected by this deletion
     $this->AffectedUsers = $this->RoleModel->GetUserCount($RoleID);
     // Figure out how many users will be orphaned by this deletion
     $this->OrphanedUsers = $this->RoleModel->GetUserCount($RoleID, TRUE);
     // Get a list of roles other than this one that can act as a replacement
     $this->ReplacementRoles = $this->RoleModel->GetByNotRoleID($RoleID);
     if ($this->Form->AuthenticatedPostBack()) {
         // Make sure that a replacement role has been selected if there were going to be orphaned users
         if ($this->OrphanedUsers > 0) {
             $Validation = new Gdn_Validation();
             $Validation->ApplyRule('ReplacementRoleID', 'Required', 'You must choose a replacement role for orphaned users.');
             $Validation->Validate($this->Form->FormValues());
             $this->Form->SetValidationResults($Validation->Results());
         }
         if ($this->Form->ErrorCount() == 0) {
             // Go ahead and delete the Role
             $this->RoleModel->Delete($RoleID, $this->Form->GetValue('ReplacementRoleID'));
             $this->RedirectUrl = Url('garden/role');
             $this->StatusMessage = Gdn::Translate('Deleting role...');
         }
     }
     $this->Render();
 }
 public function Validate($Criteria, $Form)
 {
     $Validation = new Gdn_Validation();
     $Validation->ApplyRules(array(array('Name' => 'SocialNetwork', 'Validation' => array('Required'))));
     $Validation->Validate($Criteria);
     $Form->SetValidationResults($Validation->Results());
 }
 public function Validate($Criteria, $Form)
 {
     $Validation = new Gdn_Validation();
     foreach ($Criteria as $ActionID => $Target) {
         $Validation->ApplyRule($ActionID, 'Integer');
     }
     $Validation->Validate($Criteria);
     $Form->SetValidationResults($Validation->Results());
 }
 protected function Create($Sender)
 {
     $Sender->Permission('Garden.Email.Manage');
     $Sender->CanGiveJobToCron = C('EnabledPlugins.PluginUtils') !== False;
     $Validation = new Gdn_Validation();
     $Validation->ApplyRule('RecipientEmailList', array('Required', 'ValidateEmail'));
     $Validation->ApplyRule('Subject', 'Required');
     $Validation->ApplyRule('Body', 'Required');
     $Sender->DrawConfirmSend = False;
     if ($Sender->Form->AuthenticatedPostBack() != False) {
         $FormValues = $Sender->Form->FormValues();
         $ValidationResult = $Validation->Validate($FormValues);
         $Sender->Form->SetValidationResults($Validation->Results());
         if ($ValidationResult) {
             $Emails = $this->GetUserEmails($FormValues);
             $Sender->CountEmails = count($Emails);
             if ($Sender->CountEmails == 0) {
                 $Sender->Form->AddError('No one to send');
             }
         }
         if ($Sender->Form->ErrorCount() == 0) {
             $Sender->DrawConfirmSend = True;
             if (ArrayValue('ConfirmSend', $FormValues)) {
                 $Sent = $this->Send($Emails, $FormValues);
                 if ($Sent != False) {
                     $Sender->StatusMessage = T('Your message was successfully sent.');
                 }
             }
         }
     } else {
         $SupportAddress = C('Garden.Email.SupportAddress');
         if (!$SupportAddress) {
             $SupportAddress = 'noreply@' . Gdn::Request()->Host();
         }
         $Sender->Form->SetValue('RecipientEmailList', $SupportAddress);
     }
     $Sender->View = $this->GetView('create.php');
     $RoleModel = Gdn::Factory('RoleModel');
     $Sender->RoleData = $RoleModel->Get();
     $Sender->Render();
 }
Exemple #6
0
 /**
  * @param unknown_type $FormPostValues
  * @param unknown_type $Insert
  * @return unknown
  * @todo add doc
  */
 public function Validate($FormPostValues, $Insert = FALSE)
 {
     $this->DefineSchema();
     return $this->Validation->Validate($FormPostValues, $Insert);
 }
 /**
  * Main import page.
  *
  * @since 2.0.0
  * @access public
  */
 public function Index()
 {
     $this->Permission('Garden.Import');
     // This permission doesn't exist, so only users with Admin == '1' will succeed.
     $Timer = new Gdn_Timer();
     // Determine the current step.
     $this->Form = new Gdn_Form();
     $Imp = new ImportModel();
     $Imp->LoadState();
     // Search for the list of acceptable imports.
     $ImportPaths = array();
     $ExistingPaths = SafeGlob(PATH_ROOT . '/uploads/export*', array('gz', 'txt'));
     foreach ($ExistingPaths as $Path) {
         $ImportPaths[$Path] = basename($Path);
     }
     // Add the database as a path.
     $ImportPaths = array_merge(array('db:' => T('This Database')), $ImportPaths);
     if ($Imp->CurrentStep < 1) {
         // Check to see if there is a file.
         $ImportPath = C('Garden.Import.ImportPath');
         $Validation = new Gdn_Validation();
         if (strcasecmp(Gdn::Request()->RequestMethod(), 'post') == 0) {
             $Upload = new Gdn_Upload();
             $Validation = new Gdn_Validation();
             if (count($ImportPaths) > 0) {
                 $Validation->ApplyRule('PathSelect', 'Required', T('You must select a file to import.'));
             }
             if (count($ImportPaths) == 0 || $this->Form->GetFormValue('PathSelect') == 'NEW') {
                 $TmpFile = $Upload->ValidateUpload('ImportFile', FALSE);
             } else {
                 $TmpFile = '';
             }
             if ($TmpFile) {
                 $Filename = $_FILES['ImportFile']['name'];
                 $Extension = pathinfo($Filename, PATHINFO_EXTENSION);
                 $TargetFolder = PATH_ROOT . DS . 'uploads' . DS . 'import';
                 if (!file_exists($TargetFolder)) {
                     mkdir($TargetFolder, 0777, TRUE);
                 }
                 $ImportPath = $Upload->GenerateTargetName(PATH_ROOT . DS . 'uploads' . DS . 'import', $Extension);
                 $Upload->SaveAs($TmpFile, $ImportPath);
                 $Imp->ImportPath = $ImportPath;
                 $this->Form->SetFormValue('PathSelect', $ImportPath);
                 $UploadedFiles = GetValue('UploadedFiles', $Imp->Data);
                 $UploadedFiles[$ImportPath] = basename($Filename);
                 $Imp->Data['UploadedFiles'] = $UploadedFiles;
             } elseif ($PathSelect = $this->Form->GetFormValue('PathSelect')) {
                 if ($PathSelect == 'NEW') {
                     $Validation->AddValidationResult('ImportFile', 'ValidateRequired');
                 } else {
                     $Imp->ImportPath = $PathSelect;
                 }
             } elseif (!$Imp->ImportPath && count($ImportPaths) == 0) {
                 // There was no file uploaded this request or before.
                 $Validation->AddValidationResult('ImportFile', $Upload->Exception);
             }
             // Validate the overwrite.
             if (TRUE || strcasecmp($this->Form->GetFormValue('Overwrite'), 'Overwrite') == 0) {
                 if (!StringBeginsWith($this->Form->GetFormValue('PathSelect'), 'Db:', TRUE)) {
                     $Validation->ApplyRule('Email', 'Required');
                     if (!$this->Form->GetFormValue('UseCurrentPassword')) {
                         $Validation->ApplyRule('Password', 'Required');
                     }
                 }
             }
             if ($Validation->Validate($this->Form->FormValues())) {
                 $this->Form->SetFormValue('Overwrite', 'overwrite');
                 $Imp->FromPost($this->Form->FormValues());
                 $this->View = 'Info';
             } else {
                 $this->Form->SetValidationResults($Validation->Results());
             }
         } else {
             $this->Form->SetFormValue('PathSelect', $Imp->ImportPath);
         }
         $Imp->SaveState();
     } else {
         $this->SetData('Steps', $Imp->Steps());
         $this->View = 'Info';
     }
     if (!StringBeginsWith($Imp->ImportPath, 'db:') && !file_exists($Imp->ImportPath)) {
         $Imp->DeleteState();
     }
     try {
         $UploadedFiles = GetValue('UploadedFiles', $Imp->Data, array());
         $ImportPaths = array_merge($ImportPaths, $UploadedFiles);
         $this->SetData('ImportPaths', $ImportPaths);
         $this->SetData('Header', $Imp->GetImportHeader());
         $this->SetData('Stats', GetValue('Stats', $Imp->Data, array()));
         $this->SetData('GenerateSQL', GetValue('GenerateSQL', $Imp->Data));
         $this->SetData('ImportPath', $Imp->ImportPath);
         $this->SetData('OriginalFilename', GetValue('OriginalFilename', $Imp->Data));
         $this->SetData('CurrentStep', $Imp->CurrentStep);
         $this->SetData('LoadSpeedWarning', $Imp->LoadTableType(FALSE) == 'LoadTableWithInsert');
     } catch (Gdn_UserException $Ex) {
         $this->Form->AddError($Ex);
         $Imp->SaveState();
         $this->View = 'Index';
     }
     $this->Render();
 }
 public function Index()
 {
     $this->Permission('Garden.Import');
     // This permission doesn't exist, so only users with Admin == '1' will succeed.
     $Timer = new Gdn_Timer();
     // Determine the current step.
     $this->Form = new Gdn_Form();
     $Imp = new ImportModel();
     $Imp->LoadState();
     if ($Imp->CurrentStep < 1) {
         // Check to see if there is a file.
         $ImportPath = Gdn::Config('Garden.Import.ImportPath');
         $Validation = new Gdn_Validation();
         if (strcasecmp(Gdn::Request()->RequestMethod(), 'post') == 0) {
             $Upload = new Gdn_Upload();
             $Validation = new Gdn_Validation();
             $TmpFile = $Upload->ValidateUpload('ImportFile', FALSE);
             if ($TmpFile) {
                 $Filename = $_FILES['ImportFile']['name'];
                 $Extension = pathinfo($Filename, PATHINFO_EXTENSION);
                 $TargetFolder = PATH_ROOT . DS . 'uploads' . DS . 'import';
                 if (!file_exists($TargetFolder)) {
                     mkdir($TargetFolder, 0777, TRUE);
                 }
                 $ImportPath = $Upload->GenerateTargetName(PATH_ROOT . DS . 'uploads' . DS . 'import', $Extension);
                 $Upload->SaveAs($TmpFile, $ImportPath);
                 $Imp->ImportPath = $ImportPath;
                 $Imp->Data['OriginalFilename'] = basename($Filename);
             } elseif (!$Imp->ImportPath) {
                 // There was no file uploaded this request or before.
                 $Validation->AddValidationResult('ImportFile', $Upload->Exception);
             }
             // Validate the overwrite.
             if (strcasecmp($this->Form->GetFormValue('Overwrite'), 'Overwrite') == 0) {
                 $Validation->ApplyRule('Email', 'Required');
                 $Validation->ApplyRule('Password', 'Required');
             }
             if ($Validation->Validate($this->Form->FormValues())) {
                 $Imp->Overwrite($this->Form->GetFormValue('Overwrite', 'Overwrite'), $this->Form->GetFormValue('Email'), $this->Form->GetFormValue('Password'));
                 $this->View = 'Info';
             } else {
                 $this->Form->SetValidationResults($Validation->Results());
             }
         } else {
             // Search for an existing file that was uploaded by the web admin.
             $ImportPaths = SafeGlob(PATH_ROOT . DS . 'uploads' . DS . 'import' . DS . 'import.*');
             if ($ImportPaths) {
                 $ImportPath = $ImportPaths[0];
                 if (in_array(pathinfo($ImportPath, PATHINFO_EXTENSION), array('gz', 'txt'))) {
                     $Imp->ImportPath = $ImportPath;
                     $Imp->Data['OriginalFilename'] = basename($ImportPath);
                 }
             }
         }
         $Imp->SaveState();
     } else {
         $this->View = 'Info';
     }
     $this->SetData('Header', $Imp->GetImportHeader());
     $this->SetData('ImportPath', $Imp->ImportPath);
     $this->SetData('OriginalFilename', GetValue('OriginalFilename', $Imp->Data));
     $this->Render();
 }
 /**
  * You can manually award badges to users for special cases
  *
  * @param int $UserID
  * @throws Gdn_UserException
  */
 public function Award($UserID)
 {
     // Check permission
     $this->Permission('Yaga.Badges.Add');
     $this->AddSideMenu('badge/settings');
     // Only allow awarding if some badges exist
     if (!$this->BadgeModel->GetCount()) {
         throw new Gdn_UserException(T('Yaga.Error.NoBadges'));
     }
     $UserModel = Gdn::UserModel();
     $User = $UserModel->GetID($UserID);
     $this->SetData('Username', $User->Name);
     $Badges = $this->BadgeModel->Get();
     $Badgelist = array();
     foreach ($Badges as $Badge) {
         $Badgelist[$Badge->BadgeID] = $Badge->Name;
     }
     $this->SetData('Badges', $Badgelist);
     if ($this->Form->IsPostBack() == FALSE) {
         // Add the user id field
         $this->Form->AddHidden('UserID', $User->UserID);
     } else {
         $Validation = new Gdn_Validation();
         $Validation->ApplyRule('UserID', 'ValidateRequired');
         $Validation->ApplyRule('BadgeID', 'ValidateRequired');
         if ($Validation->Validate($this->Request->Post())) {
             $FormValues = $this->Form->FormValues();
             if ($this->BadgeAwardModel->Exists($FormValues['UserID'], $FormValues['BadgeID'])) {
                 $this->Form->AddError(sprintf(T('Yaga.Badge.AlreadyAwarded'), $User->Name), 'BadgeID');
                 // Need to respecify the user id
                 $this->Form->AddHidden('UserID', $User->UserID);
             }
             if ($this->Form->ErrorCount() == 0) {
                 $this->BadgeAwardModel->Award($FormValues['BadgeID'], $FormValues['UserID'], Gdn::Session()->UserID, $FormValues['Reason']);
                 if ($this->Request->Get('Target')) {
                     $this->RedirectUrl = $this->Request->Get('Target');
                 } elseif ($this->DeliveryType() == DELIVERY_TYPE_ALL) {
                     $this->RedirectUrl = Url(UserUrl($User));
                 } else {
                     $this->JsonTarget('', '', 'Refresh');
                 }
             }
         } else {
             $this->Form->SetValidationResults($Validation->Results());
         }
     }
     $this->Render();
 }
 public function Merge()
 {
     $this->Permission('Garden.Settings.Manage');
     // This must be a postback.
     if (!$this->Request->IsAuthenticatedPostBack()) {
         throw ForbiddenException('GET');
     }
     $Validation = new Gdn_Validation();
     $Validation->ApplyRule('OldUserID', 'ValidateRequired');
     $Validation->ApplyRule('NewUserID', 'ValidateRequired');
     if ($Validation->Validate($this->Request->Post())) {
         $Result = Gdn::UserModel()->Merge($this->Request->Post('OldUserID'), $this->Request->Post('NewUserID'));
         $this->SetData($Result);
     } else {
         $this->Form->SetValidationResults($Validation->Results());
     }
     $this->Render('Blank', 'Utility');
 }
Exemple #11
0
 public function ProfileController_MyProfileEdit_Create($Sender, $Args)
 {
     $sfYaml = Gdn::Factory('sfYaml');
     $Sender->UserID = ArrayValue(0, $Args, '');
     $Sender->UserName = ArrayValue(1, $Args, '');
     $Sender->GetUserInfo($Sender->UserID, $Sender->UserName);
     $SessionUserID = Gdn::Session()->UserID;
     if ($Sender->User->UserID != $SessionUserID) {
         $Sender->Permission('Garden.Users.Edit');
         $MyMetaUserID = $Sender->User->UserID;
     } else {
         $MyMetaUserID = $SessionUserID = Gdn::Session()->UserID;
     }
     if (file_exists(dirname(__FILE__) . DS . 'mymeta.yml')) {
         $Meta = $sfYaml->load(dirname(__FILE__) . DS . 'mymeta.yml');
         $Sender->SetData('Example', false);
     } else {
         if (file_exists(dirname(__FILE__) . DS . 'mymeta.yml.example')) {
             $Meta = $sfYaml->load(dirname(__FILE__) . DS . 'mymeta.yml.example');
             $Sender->SetData('Example', true);
         }
     }
     $Sender->Form = new Gdn_Form();
     $ValidationFailed = false;
     if ($Sender->Form->AuthenticatedPostBack() === FALSE) {
         $Sender->Form->SetData($Sender->MyProfile);
     } else {
         $Data = $Sender->Form->FormValues();
         $Validation = new Gdn_Validation();
         foreach ($Data as $DataI => $DataV) {
             $Field = $Meta['MyMeta'][$DataI];
             if (GetValue('required', $Field)) {
                 $Validation->ApplyRule($DataI, 'Required', sprintf(T('%s is required'), $Field['name']));
             }
             foreach (GetValue('requiredwith', $Field) as $RequiredWith) {
                 if (!GetValue($RequiredWith, $Datarequired)) {
                     $Validation->ApplyRule($RequiredWith, 'Required', sprintf(T('%s is required with %s'), $Meta['MyMeta'][$RequiredWith]['name'], $Field['name']));
                 }
             }
             if (empty($DataV)) {
                 continue;
             }
             if ($V = GetValue('validate', $Field)) {
                 if (strpos($V, 'Validate') === 0) {
                     //Begins with
                     $V = substr($V, 8);
                     if (function_exists($V)) {
                         $Validation->AddRule($V, 'function:' . $V);
                     } else {
                         if (function_exists($V)) {
                             $Validation->AddRule($V, 'function:Validate' . $V);
                         }
                     }
                 }
                 $Validation->ApplyRule($DataI, $V, sprintf(T('%s not valid'), $Field['name']));
             }
             if ($R = GetValue('validateregex', $Field)) {
                 $Validation->AddRule($DataI, 'regex:`^' . $R . '$`i');
                 $Validation->ApplyRule($DataI, $DataI, sprintf(T('%s not valid'), $Field['name']));
             }
             if ($M = GetValue('maxchar', $Field)) {
                 $Validation->AddRule('MaxLen' . $DataI, 'regex:`^.{0,' . $M . '}$`is');
                 $Validation->ApplyRule($DataI, 'MaxLen' . $DataI, sprintf(T('%s not cannot be longer than %s chars'), $Field['name'], $M));
             }
         }
         $Validation->Validate($Data);
         if (count($Validation->Results()) == 0) {
             $MyMeta = array_intersect_key($Data, $Meta['MyMeta']);
             UserModel::SetMeta($MyMetaUserID, $MyMeta, 'MyMeta.');
         } else {
             $ValidationFailed = true;
         }
         $Sender->Form->SetValidationResults($Validation->Results());
     }
     if (!$ValidationFailed) {
         $Data = UserModel::GetMeta($MyMetaUserID, 'MyMeta.%', 'MyMeta.');
     }
     $MyMeta = array_intersect_key($Data, $Meta['MyMeta']);
     $Sender->SetData('Fields', $Meta['MyMeta']);
     $Sender->SetData('MyMeta', $MyMeta);
     $Sender->View = dirname(__FILE__) . DS . 'views' . DS . 'edit.php';
     $Sender->Render();
 }
Exemple #12
0
 /**
  * @param unknown_type $FormPostValues
  * @param unknown_type $Insert
  * @return unknown
  * @todo add doc
  */
 public function Validate($FormPostValues, $Insert = FALSE)
 {
     return $this->Validation->Validate($FormPostValues, $Insert);
 }
 /**
  * You can manually award ranks to users for special cases
  *
  * @param int $UserID
  * @throws Gdn_UserException
  */
 public function Promote($UserID)
 {
     // Check permission
     $this->Permission('Yaga.Ranks.Add');
     $this->AddSideMenu('rank/settings');
     // Only allow awarding if some ranks exist
     if (!$this->RankModel->GetCount()) {
         throw new Gdn_UserException(T('Yaga.Error.NoRanks'));
     }
     $UserModel = Gdn::UserModel();
     $User = $UserModel->GetID($UserID);
     $this->SetData('Username', $User->Name);
     $Ranks = $this->RankModel->Get();
     $Ranklist = array();
     foreach ($Ranks as $Rank) {
         $Ranklist[$Rank->RankID] = $Rank->Name;
     }
     $this->SetData('Ranks', $Ranklist);
     if ($this->Form->IsPostBack() == FALSE) {
         // Add the user id field
         $this->Form->AddHidden('UserID', $User->UserID);
     } else {
         $Validation = new Gdn_Validation();
         $Validation->ApplyRule('UserID', 'ValidateRequired');
         $Validation->ApplyRule('RankID', 'ValidateRequired');
         if ($Validation->Validate($this->Request->Post())) {
             $FormValues = $this->Form->FormValues();
             if ($this->Form->ErrorCount() == 0) {
                 $this->RankModel->Set($FormValues['RankID'], $FormValues['UserID'], $FormValues['RecordActivity']);
                 $UserModel->SetField($UserID, 'RankProgression', $FormValues['RankProgression']);
                 if ($this->Request->Get('Target')) {
                     $this->RedirectUrl = $this->Request->Get('Target');
                 } elseif ($this->DeliveryType() == DELIVERY_TYPE_ALL) {
                     $this->RedirectUrl = Url(UserUrl($User));
                 } else {
                     $this->JsonTarget('', '', 'Refresh');
                 }
             }
         } else {
             $this->Form->SetValidationResults($Validation->Results());
         }
     }
     $this->Render();
 }