function do_newPermission()
 {
     session_start();
     $sName = KTUtil::arrayGet($_REQUEST, 'name');
     $sHumanName = KTUtil::arrayGet($_REQUEST, 'human_name');
     $sError = 'An error occured while creating your permission';
     //Checking that the System Name and Display Name fields aren't empty
     if (empty($sName) && !empty($sHumanName)) {
         $sError = 'An error occured while creating your permission: The System Name was not provided.';
         $_SESSION['Permission']['HumanNameValue'] = $sHumanName;
         return $this->errorRedirectToMain(_kt($sError));
     } else {
         if (!empty($sName) && empty($sHumanName)) {
             $sError = 'An error occured while creating your permission: The Display Name was not provided.';
             $_SESSION['Permission']['NameValue'] = $sName;
             return $this->errorRedirectToMain(_kt($sError));
         } else {
             if (empty($sName) && empty($sHumanName)) {
                 $sError = 'An error occured while creating your permission: The Display Name and System Name weren\'t provided.';
                 return $this->errorRedirectToMain(_kt($sError));
             }
         }
     }
     //Checking that the System Name and Display Name aren't already in the database
     $aPermissions = KTPermission::getList();
     //$iNameErrorCount and $iHumanNameErrorCount are used to check whether only one name is duplicated or if two names are duplicated.
     $iNameErrorCount = 0;
     $iHumanNameErrorCount = 0;
     foreach ($aPermissions as $aPermission) {
         if ($sName == $aPermission->getName()) {
             $iNameErrorCount++;
         }
         if ($sHumanName == $aPermission->getHumanName()) {
             $iHumanNameErrorCount++;
         }
     }
     if ($iNameErrorCount > 0 && $iHumanNameErrorCount > 0) {
         $sError = 'An error occured while creating your permission: The Display Name and System Name you have provided both already exist.';
         return $this->errorRedirectToMain(_kt($sError));
     } else {
         if ($iNameErrorCount > 0 && $iHumanNameErrorCount == 0) {
             if (!empty($sHumanName)) {
                 $_SESSION['Permission']['HumanNameValue'] = $sHumanName;
             }
             $sError = 'An error occured while creating your permission: A permission with the same System Name already exists.';
             return $this->errorRedirectToMain(_kt($sError));
         } else {
             if ($iNameErrorCount == 0 && $iHumanNameErrorCount > 0) {
                 if (!empty($sName)) {
                     $_SESSION['Permission']['NameValue'] = $sName;
                 }
                 $sError = 'An error occured while creating your permission: A permission with the same Display Name already exists.';
                 return $this->errorRedirectToMain(_kt($sError));
             }
         }
     }
     $oPerm = KTPermission::createFromArray(array('name' => $sName, 'humanname' => $sHumanName));
     if (PEAR::isError($oPerm)) {
         return $this->errorRedirectToMain(_kt($sError));
     }
     return $this->successRedirectToMain(_kt("Permission created"));
 }
Exemple #2
0
<?php

require_once "../../config/dmsDefaults.php";
require_once KT_LIB_DIR . "/permissions/permission.inc.php";
error_reporting(E_ALL);
// var_dump(KTHelpReplacement::get(1));
$res = KTPermission::createFromArray(array());