コード例 #1
0
 public function loadCreatePermission($parameters)
 {
     $errors = array();
     if (isset($_POST['permission_name'])) {
         //Check for length
         if ($_POST['permission_name'] == "") {
             $errors[] = "Name cannot be blank.";
         }
         //Check for whitespace in the abbreviation
         if (stristr($_POST['permission_name'], ' ')) {
             $errors[] = "Abbreviation cannot contain whitespace.";
         }
         //Check the name for uniqueness
         if (!DinklyPermissionCollection::isUniqueName($_POST['permission_name'])) {
             $errors[] = "Name already in use, please try another.";
         }
         //Make sure that the abbreviation is also alphanumeric, without funky symbols
         $valid_symbols = array('-', '_');
         if (!ctype_alnum(str_replace($valid_symbols, '', $_POST['permission_name']))) {
             $errors[] = "Name must be alphanumeric. Underscores and dashes are allowed.";
         }
         if ($errors != array()) {
             echo implode('<br>', $errors);
         } else {
             $permission = new DinklyPermission();
             $permission->setName($_POST['permission_name']);
             $permission->setDescription($_POST['permission_description']);
             $permission->save();
             echo 'success';
         }
     }
     return false;
 }