예제 #1
0
 function assertNotValid($data, $errors)
 {
     $validator = new Validator();
     $validator->check($data, $this->schema);
     $this->assertEquals($errors, $validator->getErrors(), print_r($validator->getErrors(), true));
     $this->assertFalse($validator->isValid());
 }
예제 #2
0
 public function img_profil($db, $user_id, $image, $path)
 {
     $validator = new Validator($_POST);
     $validator->isSize($image, 'Votre photo est trop lourde.');
     $validator->isExtension($image, 'Vous ne pouvez mettre que des fichiers avec les extensions suivantes : png, gif, jpg, jpeg.');
     $uploadfile = basename($_FILES[$image]['name']);
     $uploadfile = strtr($uploadfile, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
     $img = $path . $uploadfile;
     if ($validator->isValid()) {
         $this->field_img($db, $user_id, $img, $image);
         move_uploaded_file($_FILES[$image]['tmp_name'], $img);
         $info_user = $this->checkId($db, $user_id);
         return $info_user->image = $img;
     } else {
         return $errors = $validator->getErrors();
     }
 }
예제 #3
0
 public function validate()
 {
     require_once 'validator.class.php';
     $data = $_POST;
     //     $data = array(
     //					"emailId"=>"*****@*****.**",
     //					"password" => "",
     //        			"fullName" => "",
     //      );
     // define the rules
     $rules = array("emailId" => "email", "password" => "require", "fullName" => "require");
     $message = array("email" => array("require" => "Email Id is Required", "email" => 'Valid EmailId Only'), "password" => "Password is Required", "fullName" => "Full Name is Required");
     $objValidator = new Validator($rules, $message);
     if (!$objValidator->isValid($data)) {
         return false;
     } else {
         return true;
     }
 }
예제 #4
0
<?php

require_once '../autoload.php';
require_once '../include/results.php';
//rajouter order bye et condition si reply ou origine et recuper donner(function dans class)
$tweet = new Tweet($user_id);
// $tweet->getIdTweet();
/*var_dump($p = new Tweet($user_id, 2));
var_dump($p->getIdTweet());*/
// var_dump($p = new Tweet($user_id));
// var_dump($p->Tweet_follower($user_id));
if (isset($_FILES['file-input']) && !empty($_FILES['file-input']['name'])) {
    $uploaddir = '../view/img-user/tweet/';
    $validator = new Validator($_POST);
    $validator->isSize('file-input', 'You picture is too oversized');
    $validator->isExtension('file-input', 'You must upload a type of picture with png, gif, jpg, jpeg, please.');
    $uploadfile = basename($_FILES['file-input']['name']);
    $uploadfile = strtr($uploadfile, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
    $img_tweet = $uploaddir . $uploadfile;
    if ($validator->isValid()) {
        move_uploaded_file($_FILES['file-input']['tmp_name'], $img_tweet);
        $tweet->newTweet($img_tweet);
        /*$info_user->avatar = $avatar;*/
    } else {
        $errors = $validator->getErrors();
    }
} else {
    $tweet->newTweet();
}
require_once '../view/accueil.php';
예제 #5
0
파일: ValidatorB3.php 프로젝트: bmdevel/bav
 /**
  * @return bool
  */
 protected function getResult()
 {
     return $this->validator->isValid($this->account);
 }
예제 #6
0
파일: ValidatorC5.php 프로젝트: bmdevel/bav
 /**
  * @return bool
  */
 protected function getResult()
 {
     return !is_null($this->validator) && $this->validator->isValid($this->account);
 }
 /**
  * Delete one or more users.
  * @param array $data user data
  * @return array
  */
 function deleteUserGenericData($data)
 {
     Debug::Arr($data, 'DataA: ', __FILE__, __LINE__, __METHOD__, 10);
     if (is_numeric($data)) {
         $data = array($data);
     }
     if (!is_array($data)) {
         return $this->returnHandler(FALSE);
     }
     Debug::Text('Received data for: ' . count($data) . ' Users', __FILE__, __LINE__, __METHOD__, 10);
     Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10);
     $total_records = count($data);
     $validator_stats = array('total_records' => $total_records, 'valid_records' => 0);
     if (is_array($data)) {
         foreach ($data as $key => $id) {
             $primary_validator = new Validator();
             $lf = TTnew('UserGenericDataListFactory');
             $lf->StartTransaction();
             if (is_numeric($id)) {
                 //Modifying existing object.
                 //Get user object, so we can only modify just changed data for specific records if needed.
                 $lf->getByUserIdAndId($this->getCurrentUserObject()->getId(), $id);
                 if ($lf->getRecordCount() == 1) {
                     //Object exists
                     Debug::Text('User Generic Data Exists, deleting record: ', $id, __FILE__, __LINE__, __METHOD__, 10);
                     $lf = $lf->getCurrent();
                 } else {
                     //Object doesn't exist.
                     $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, generic data does not exist'));
                 }
             } else {
                 $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, generic data does not exist'));
             }
             //Debug::Arr($lf, 'AData: ', __FILE__, __LINE__, __METHOD__, 10);
             $is_valid = $primary_validator->isValid();
             if ($is_valid == TRUE) {
                 //Check to see if all permission checks passed before trying to save data.
                 Debug::Text('Attempting to delete user generic data...', __FILE__, __LINE__, __METHOD__, 10);
                 $lf->setDeleted(TRUE);
                 $is_valid = $lf->isValid();
                 if ($is_valid == TRUE) {
                     Debug::Text('User Deleted...', __FILE__, __LINE__, __METHOD__, 10);
                     $save_result[$key] = $lf->Save();
                     $validator_stats['valid_records']++;
                 }
             }
             if ($is_valid == FALSE) {
                 Debug::Text('User Generic Data is Invalid...', __FILE__, __LINE__, __METHOD__, 10);
                 $lf->FailTransaction();
                 //Just rollback this single record, continue on to the rest.
                 if ($primary_validator->isValid() == FALSE) {
                     $validator[$key] = $primary_validator->getErrorsArray();
                 } else {
                     $validator[$key] = $lf->Validator->getErrorsArray();
                 }
             }
             $lf->CommitTransaction();
         }
         if ($validator_stats['valid_records'] > 0 and $validator_stats['total_records'] == $validator_stats['valid_records']) {
             if ($validator_stats['total_records'] == 1) {
                 return $this->returnHandler($save_result[$key]);
                 //Single valid record
             } else {
                 return $this->returnHandler(TRUE, 'SUCCESS', TTi18n::getText('MULTIPLE RECORDS SAVED'), $save_result, $validator_stats);
                 //Multiple valid records
             }
         } else {
             return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats);
         }
     }
     return $this->returnHandler(FALSE);
 }
예제 #8
0
<?php

/// Copyright (c) 2004-2016, Needlworks  / Tatter Network Foundation
/// All rights reserved. Licensed under the GPL.
/// See the GNU General Public License for more details. (/documents/LICENSE, /documents/COPYRIGHT)
define('__TEXTCUBE_ADMINPANEL__', true);
require ROOT . '/library/preprocessor.php';
importlib('model.blog.comment');
$IV = array('POST' => array('name' => array('string', 'default' => ''), 'comment' => array('string', 'default' => ''), 'mode' => array(array('commit'), 'default' => ''), 'homepage' => array('string', 'default' => ''), 'password' => array('string', 'default' => ''), 'secret' => array(array('on'), 'default' => null)));
$context = Model_Context::getInstance();
$customIV = fireEvent('ManipulateIVRules', $IV, $context->getProperty('uri.interfaceRoute'));
Validator::addRule($customIV);
if (!Validator::isValid()) {
    Respond::PrintResult(array('error' => 1, 'description' => 'Illegal parameters'));
}
requireStrictRoute();
if (!Setting::getBlogSettingGlobal('acceptComments', 0) && !doesHaveOwnership()) {
    Respond::PrintResult(array('error' => 0, 'commentBlock' => '', 'recentCommentBlock' => ''));
    exit;
}
$pool = DBModel::getInstance();
if ((doesHaveMembership() || !empty($_POST['name'])) && !empty($_POST['comment']) && !empty($_POST['mode']) && $_POST['mode'] == 'commit') {
    if (!empty($_POST['name'])) {
        setcookie('guestName', $_POST['name'], time() + 2592000, $context->getProperty('uri.blog') . "/");
    }
    if (!empty($_POST['homepage']) && $_POST['homepage'] != 'http://') {
        if (strpos($_POST['homepage'], 'http://') === 0) {
            setcookie('guestHomepage', $_POST['homepage'], time() + 2592000, $context->getProperty('uri.blog') . "/");
        } else {
            setcookie('guestHomepage', 'http://' . $_POST['homepage'], time() + 2592000, $context->getProperty('uri.blog') . "/");
        }
예제 #9
0
include_once '../autoloader.php';
// Test data
$v = new Validator(['name' => 'asdfsdf', 'age' => '20', 'phone' => '123123', 'email' => '*****@*****.**', 'password' => 'wang1@']);
// Validate one field with multiple rules
$v->validate('name', ['notEmpty', ['greaterThan', 100], ['between', 0, 20]]);
$v->validate('age', ['notEmpty', ['between', 0, 100]]);
//length validation
//equal validation
$v->validate('name', [['length', 7]]);
$v->validate('name', [['equal', true]]);
// Email
$v->email()->validate('age', [['EmailValidator', '123.com']]);
// Call additional validator
echo $v->address()->street(3) . '<br>';
// Use getKey method to validate key value
echo $v->phone()->phoneNumber('12345') . '<br>';
echo $v->phone()->phoneNumber($v->getKey('phone')) . '<br>';
echo 'street', $v->address()->validate('email', ['street']) . '<br>';
//password validation
echo $v->password()->password($v->getKey('password')) . '<br>';
// Errors
echo '<hr/>';
if ($v->isValid()) {
    echo 'all valid';
} else {
    echo 'error on age field: ';
    $v->displayError('age');
    echo 'All errors';
    $v->displayErrorAll();
}
echo '<hr/>';
예제 #10
0
<?php

echo "welcome to VALIDATOR";
class Validator
{
    private $pattern = "Sean";
    function isValid($string)
    {
        if ($string == $this->pattern) {
            return true;
        } else {
            return false;
        }
    }
}
$myValidator = new Validator();
if ($myValidator->isValid('Sean')) {
    echo "You are valid";
} else {
    echo "You are NOT valid!!!!";
}
예제 #11
0
        if (preg_match($this->pattern, $string)) {
            return true;
        } else {
            return false;
        }
    }
}
$puppyValidator = new Validator();
if (isset($_SESSION["dogs"])) {
    $dogs = $_SESSION["dogs"];
}
if (isset($_POST["pup_name"])) {
    $name = $_POST["pup_name"];
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if ($puppyValidator->isValid($name)) {
        array_push($dogs, $name);
        $_SESSION["dogs"] = $dogs;
    } else {
        $msg = "bad puppy name";
    }
}
foreach ($dogs as $value) {
    $list .= "<li>" . $value . "<button class='remove'>X</button>" . "</li>";
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
예제 #12
0
 /**
  * Set log data for one or more loges.
  * @param array $data log data
  * @return array
  */
 function setLog($data, $validate_only = FALSE)
 {
     $validate_only = (bool) $validate_only;
     if (!is_array($data)) {
         return $this->returnHandler(FALSE);
     }
     if ($validate_only == TRUE) {
         Debug::Text('Validating Only!', __FILE__, __LINE__, __METHOD__, 10);
     }
     extract($this->convertToMultipleRecords($data));
     Debug::Text('Received data for: ' . $total_records . ' Logs', __FILE__, __LINE__, __METHOD__, 10);
     Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10);
     $validator_stats = array('total_records' => $total_records, 'valid_records' => 0);
     if (is_array($data)) {
         $this->getProgressBarObject()->start($this->getAMFMessageID(), $total_records);
         foreach ($data as $key => $row) {
             $primary_validator = new Validator();
             $lf = TTnew('LogListFactory');
             $lf->StartTransaction();
             //Can add log entries only.
             unset($row['id']);
             Debug::Arr($row, 'Data: ', __FILE__, __LINE__, __METHOD__, 10);
             Debug::Text('Setting object data...', __FILE__, __LINE__, __METHOD__, 10);
             $lf->setObjectFromArray($row);
             //Force Company ID to current company.
             $lf->setUser($this->getCurrentUserObject()->getId());
             $is_valid = $lf->isValid();
             if ($is_valid == TRUE) {
                 Debug::Text('Saving data...', __FILE__, __LINE__, __METHOD__, 10);
                 if ($validate_only == TRUE) {
                     $save_result[$key] = TRUE;
                 } else {
                     $save_result[$key] = $lf->Save();
                 }
                 $validator_stats['valid_records']++;
             }
             if ($is_valid == FALSE) {
                 Debug::Text('Data is Invalid...', __FILE__, __LINE__, __METHOD__, 10);
                 $lf->FailTransaction();
                 //Just rollback this single record, continue on to the rest.
                 if ($primary_validator->isValid() == FALSE) {
                     $validator[$key] = $primary_validator->getErrorsArray();
                 } else {
                     $validator[$key] = $lf->Validator->getErrorsArray();
                 }
             }
             $lf->CommitTransaction();
             $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
         }
         $this->getProgressBarObject()->stop($this->getAMFMessageID());
         if ($validator_stats['valid_records'] > 0 and $validator_stats['total_records'] == $validator_stats['valid_records']) {
             if ($validator_stats['total_records'] == 1) {
                 return $this->returnHandler($save_result[$key]);
                 //Single valid record
             } else {
                 return $this->returnHandler(TRUE, 'SUCCESS', TTi18n::getText('MULTIPLE RECORDS SAVED'), $save_result, $validator_stats);
                 //Multiple valid records
             }
         } else {
             return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats);
         }
     }
     return $this->returnHandler(FALSE);
 }
 /**
  * Delete one or more recurring_schedule_controls.
  * @param array $data recurring_schedule_control data
  * @return array
  */
 function deleteRecurringScheduleControl($data)
 {
     if (is_numeric($data)) {
         $data = array($data);
     }
     if (!is_array($data)) {
         return $this->returnHandler(FALSE);
     }
     if (!$this->getPermissionObject()->Check('recurring_schedule', 'enabled') or !($this->getPermissionObject()->Check('recurring_schedule', 'delete') or $this->getPermissionObject()->Check('recurring_schedule', 'delete_own') or $this->getPermissionObject()->Check('recurring_schedule', 'delete_child'))) {
         return $this->getPermissionObject()->PermissionDenied();
     }
     //Get Permission Hierarchy Children first, as this can be used for viewing, or editing.
     $permission_children_ids = $this->getPermissionChildren();
     Debug::Text('Received data for: ' . count($data) . ' RecurringScheduleControls', __FILE__, __LINE__, __METHOD__, 10);
     Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10);
     $total_records = count($data);
     $validator_stats = array('total_records' => $total_records, 'valid_records' => 0);
     if (is_array($data)) {
         $this->getProgressBarObject()->start($this->getAMFMessageID(), $total_records);
         foreach ($data as $key => $tmp_id) {
             $primary_validator = new Validator();
             $lf = TTnew('RecurringScheduleControlListFactory');
             $lf->StartTransaction();
             //Need to support deleting the entire recurring schedule, or just one user from it.
             if (is_array($tmp_id)) {
                 $id = $key;
                 $user_id = $tmp_id;
                 Debug::Arr($tmp_id, 'ID is an array, with User ID specified as well, deleting just this one user: ID: ' . $id . ' User IDs: ', __FILE__, __LINE__, __METHOD__, 10);
             } else {
                 $id = $tmp_id;
                 $user_id = FALSE;
             }
             if (is_numeric($id)) {
                 //Modifying existing object.
                 //Get recurring_schedule_control object, so we can only modify just changed data for specific records if needed.
                 $lf->getByIdAndCompanyId($id, $this->getCurrentCompanyObject()->getId());
                 if ($lf->getRecordCount() == 1) {
                     //Object exists, check edit permissions
                     if ($this->getPermissionObject()->Check('recurring_schedule', 'delete') or $this->getPermissionObject()->Check('recurring_schedule', 'delete_own') and $this->getPermissionObject()->isOwner($lf->getCurrent()->getCreatedBy(), $lf->getCurrent()->getID()) === TRUE or $this->getPermissionObject()->Check('recurring_schedule', 'delete_child') and $this->getPermissionObject()->isChild($user_id, $permission_children_ids) === TRUE) {
                         //if ( $this->getPermissionObject()->Check('recurring_schedule','delete')
                         //		OR ( $this->getPermissionObject()->Check('recurring_schedule','delete_own') AND $this->getPermissionObject()->isOwner( $lf->getCurrent()->getCreatedBy(), $lf->getCurrent()->getID() ) === TRUE ) ) {
                         Debug::Text('Record Exists, deleting record: ', $id, __FILE__, __LINE__, __METHOD__, 10);
                         $lf = $lf->getCurrent();
                     } else {
                         $primary_validator->isTrue('permission', FALSE, TTi18n::gettext('Delete permission denied'));
                     }
                 } else {
                     //Object doesn't exist.
                     $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist'));
                 }
             } else {
                 $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist'));
             }
             //Debug::Arr($lf, 'AData: ', __FILE__, __LINE__, __METHOD__, 10);
             $is_valid = $primary_validator->isValid();
             if ($is_valid == TRUE) {
                 //Check to see if all permission checks passed before trying to save data.
                 Debug::Text('Attempting to delete record...', __FILE__, __LINE__, __METHOD__, 10);
                 if ($user_id > 0) {
                     //Remove this user_id from the user array.
                     $new_user_ids = array_diff((array) $lf->getUser(), (array) $user_id);
                     Debug::Arr($new_user_ids, 'Removing individual users from schedule, remaining users are: ', __FILE__, __LINE__, __METHOD__, 10);
                     if (count($new_user_ids) > 0) {
                         $lf->setUser($new_user_ids);
                     } else {
                         //No users left, delete the entire recurring schedule.
                         Debug::Text('No users left in schedule, removing entire schedule...', __FILE__, __LINE__, __METHOD__, 10);
                         $lf->setDeleted(TRUE);
                     }
                     unset($new_user_ids);
                 } else {
                     $lf->setDeleted(TRUE);
                 }
                 $is_valid = $lf->isValid();
                 if ($is_valid == TRUE) {
                     Debug::Text('Record Deleted...', __FILE__, __LINE__, __METHOD__, 10);
                     $save_result[$key] = $lf->Save();
                     $validator_stats['valid_records']++;
                 }
             }
             if ($is_valid == FALSE) {
                 Debug::Text('Data is Invalid...', __FILE__, __LINE__, __METHOD__, 10);
                 $lf->FailTransaction();
                 //Just rollback this single record, continue on to the rest.
                 if ($primary_validator->isValid() == FALSE) {
                     $validator[$key] = $primary_validator->getErrorsArray();
                 } else {
                     $validator[$key] = $lf->Validator->getErrorsArray();
                 }
             }
             $lf->CommitTransaction();
             $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
         }
         $this->getProgressBarObject()->stop($this->getAMFMessageID());
         if ($validator_stats['valid_records'] > 0 and $validator_stats['total_records'] == $validator_stats['valid_records']) {
             if ($validator_stats['total_records'] == 1) {
                 return $this->returnHandler($save_result[$key]);
                 //Single valid record
             } else {
                 return $this->returnHandler(TRUE, 'SUCCESS', TTi18n::getText('MULTIPLE RECORDS SAVED'), $save_result, $validator_stats);
                 //Multiple valid records
             }
         } else {
             return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats);
         }
     }
     return $this->returnHandler(FALSE);
 }
 protected function doTestIsNotValid(Validator $validator, $value, $errorMessages)
 {
     $this->assertFalse($validator->isValid($value));
     $this->assertNotEquals(0, count($validator->getMessages()));
     $this->assertEquals($errorMessages, $validator->getMessages());
 }
예제 #15
0
 /**
  * Delete one or more UserPreferences.
  * @param array $data UserPreference data
  * @return array
  */
 function deleteUserPreference($data)
 {
     if (is_numeric($data)) {
         $data = array($data);
     }
     if (!is_array($data)) {
         return $this->returnHandler(FALSE);
     }
     if (!$this->getPermissionObject()->Check('user_preference', 'enabled') or !($this->getPermissionObject()->Check('user_preference', 'delete') or $this->getPermissionObject()->Check('user_preference', 'delete_own') or $this->getPermissionObject()->Check('user_preference', 'delete_child'))) {
         return $this->getPermissionObject()->PermissionDenied();
     }
     Debug::Text('Received data for: ' . count($data) . ' UserPreferences', __FILE__, __LINE__, __METHOD__, 10);
     Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10);
     $total_records = count($data);
     $validator_stats = array('total_records' => $total_records, 'valid_records' => 0);
     if (is_array($data)) {
         $this->getProgressBarObject()->start($this->getAMFMessageID(), $total_records);
         foreach ($data as $key => $id) {
             $primary_validator = new Validator();
             $lf = TTnew('UserPreferenceListFactory');
             $lf->StartTransaction();
             if (is_numeric($id)) {
                 //Modifying existing object.
                 //Get UserPreference object, so we can only modify just changed data for specific records if needed.
                 $lf->getByIdAndCompanyId($id, $this->getCurrentCompanyObject()->getId());
                 if ($lf->getRecordCount() == 1) {
                     //Object exists, check edit permissions
                     if ($this->getPermissionObject()->Check('user_preference', 'delete') or $this->getPermissionObject()->Check('user_preference', 'delete_own') and $this->getPermissionObject()->isOwner($lf->getCurrent()->getCreatedBy(), $lf->getCurrent()->getID()) === TRUE) {
                         Debug::Text('Record Exists, deleting record: ', $id, __FILE__, __LINE__, __METHOD__, 10);
                         $lf = $lf->getCurrent();
                     } else {
                         $primary_validator->isTrue('permission', FALSE, TTi18n::gettext('Delete permission denied'));
                     }
                 } else {
                     //Object doesn't exist.
                     $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist'));
                 }
             } else {
                 $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist'));
             }
             //Debug::Arr($lf, 'AData: ', __FILE__, __LINE__, __METHOD__, 10);
             $is_valid = $primary_validator->isValid();
             if ($is_valid == TRUE) {
                 //Check to see if all permission checks passed before trying to save data.
                 Debug::Text('Attempting to delete record...', __FILE__, __LINE__, __METHOD__, 10);
                 $lf->setDeleted(TRUE);
                 $is_valid = $lf->isValid();
                 if ($is_valid == TRUE) {
                     Debug::Text('Record Deleted...', __FILE__, __LINE__, __METHOD__, 10);
                     $save_result[$key] = $lf->Save();
                     $validator_stats['valid_records']++;
                 }
             }
             if ($is_valid == FALSE) {
                 Debug::Text('Data is Invalid...', __FILE__, __LINE__, __METHOD__, 10);
                 $lf->FailTransaction();
                 //Just rollback this single record, continue on to the rest.
                 if ($primary_validator->isValid() == FALSE) {
                     $validator[$key] = $primary_validator->getErrorsArray();
                 } else {
                     $validator[$key] = $lf->Validator->getErrorsArray();
                 }
             }
             $lf->CommitTransaction();
             $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
         }
         $this->getProgressBarObject()->stop($this->getAMFMessageID());
         if ($validator_stats['valid_records'] > 0 and $validator_stats['total_records'] == $validator_stats['valid_records']) {
             if ($validator_stats['total_records'] == 1) {
                 return $this->returnHandler($save_result[$key]);
                 //Single valid record
             } else {
                 return $this->returnHandler(TRUE, 'SUCCESS', TTi18n::getText('MULTIPLE RECORDS SAVED'), $save_result, $validator_stats);
                 //Multiple valid records
             }
         } else {
             return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats);
         }
     }
     return $this->returnHandler(FALSE);
 }
예제 #16
0
 /**
  * Delete one or more users.
  * @param array $data user data
  * @return array
  */
 function deleteUser($data)
 {
     if (is_numeric($data)) {
         $data = array($data);
     }
     if (DEMO_MODE == TRUE) {
         return $this->returnHandler(TRUE);
     }
     if (!is_array($data)) {
         return $this->returnHandler(FALSE);
     }
     if (!$this->getPermissionObject()->Check('user', 'enabled') or !($this->getPermissionObject()->Check('user', 'delete') or $this->getPermissionObject()->Check('user', 'delete_own') or $this->getPermissionObject()->Check('user', 'delete_child'))) {
         return $this->getPermissionObject()->PermissionDenied();
     }
     //Get Permission Hierarchy Children first, as this can be used for viewing, or editing.
     $permission_children_ids = $this->getPermissionChildren();
     Debug::Text('Received data for: ' . count($data) . ' Users', __FILE__, __LINE__, __METHOD__, 10);
     Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10);
     $total_records = count($data);
     $validator_stats = array('total_records' => $total_records, 'valid_records' => 0);
     if (is_array($data)) {
         $this->getProgressBarObject()->start($this->getAMFMessageID(), $total_records);
         foreach ($data as $key => $id) {
             $primary_validator = new Validator();
             $lf = TTnew('UserListFactory');
             $lf->StartTransaction();
             if (is_numeric($id)) {
                 if ($this->getPermissionObject()->Check('company', 'view') == TRUE) {
                     $lf->getById($id);
                     //Allow deleting employees in other companies.
                 } else {
                     $lf->getByIdAndCompanyId($id, $this->getCurrentCompanyObject()->getId());
                 }
                 if ($lf->getRecordCount() == 1) {
                     //Object exists, check edit permissions
                     //Debug::Text('User ID: '. $user['id'] .' Created By: '. $lf->getCurrent()->getCreatedBy() .' Is Owner: '. (int)$this->getPermissionObject()->isOwner( $lf->getCurrent()->getCreatedBy(), $lf->getCurrent()->getID() ) .' Is Child: '. (int)$this->getPermissionObject()->isChild( $lf->getCurrent()->getId(), $permission_children_ids ), __FILE__, __LINE__, __METHOD__, 10);
                     if ($this->getPermissionObject()->Check('user', 'delete') or $this->getPermissionObject()->Check('user', 'delete_own') and $this->getPermissionObject()->isOwner($lf->getCurrent()->getCreatedBy(), $lf->getCurrent()->getID()) === TRUE or $this->getPermissionObject()->Check('user', 'delete_child') and $this->getPermissionObject()->isChild($lf->getCurrent()->getId(), $permission_children_ids) === TRUE) {
                         Debug::Text('Record Exists, deleting record: ', $id, __FILE__, __LINE__, __METHOD__, 10);
                         $lf = $lf->getCurrent();
                     } else {
                         $primary_validator->isTrue('permission', FALSE, TTi18n::gettext('Delete permission denied'));
                     }
                 } else {
                     //Object doesn't exist.
                     $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist'));
                 }
             } else {
                 $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist'));
             }
             //Debug::Arr($lf, 'AData: ', __FILE__, __LINE__, __METHOD__, 10);
             $is_valid = $primary_validator->isValid();
             if ($is_valid == TRUE) {
                 //Check to see if all permission checks passed before trying to save data.
                 Debug::Text('Attempting to delete record...', __FILE__, __LINE__, __METHOD__, 10);
                 $lf->setDeleted(TRUE);
                 $is_valid = $lf->isValid();
                 if ($is_valid == TRUE) {
                     Debug::Text('Record Deleted...', __FILE__, __LINE__, __METHOD__, 10);
                     $save_result[$key] = $lf->Save();
                     $validator_stats['valid_records']++;
                 }
             }
             if ($is_valid == FALSE) {
                 Debug::Text('Data is Invalid...', __FILE__, __LINE__, __METHOD__, 10);
                 $lf->FailTransaction();
                 //Just rollback this single record, continue on to the rest.
                 if ($primary_validator->isValid() == FALSE) {
                     $validator[$key] = $primary_validator->getErrorsArray();
                 } else {
                     $validator[$key] = $lf->Validator->getErrorsArray();
                 }
             }
             $lf->CommitTransaction();
             $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
         }
         $this->getProgressBarObject()->stop($this->getAMFMessageID());
         if ($validator_stats['valid_records'] > 0 and $validator_stats['total_records'] == $validator_stats['valid_records']) {
             if ($validator_stats['total_records'] == 1) {
                 return $this->returnHandler($save_result[$key]);
                 //Single valid record
             } else {
                 return $this->returnHandler(TRUE, 'SUCCESS', TTi18n::getText('MULTIPLE RECORDS SAVED'), $save_result, $validator_stats);
                 //Multiple valid records
             }
         } else {
             return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats);
         }
     }
     return $this->returnHandler(FALSE);
 }
예제 #17
0
파일: ValidatorB0.php 프로젝트: bmdevel/bav
 /**
  * @return bool
  */
 protected function getResult()
 {
     return strlen(ltrim($this->account, '0')) === 10 && $this->account[0] !== '8' && $this->validator->isValid($this->account);
 }