Пример #1
0
 public static function inScriptPermissionsCheck($user_id, $showMenuIfFailed)
 {
     $pageURI = $_SERVER['REQUEST_URI'];
     if (!Permissions::hasPermissionsForScript($user_id, $pageURI)) {
         if ($showMenuIfFailed) {
             include dirname(dirname(__FILE__)) . '/include/header.include.php';
         } else {
             echo '<html><head></head><body>';
         }
         echo '<h3>You need the following permissions to use this page:</h3>';
         echo '<ul>';
         $fileCache = self::createFileCache();
         $db = null;
         $ps = new PreparedStatement('select description from appperm where perm_name = ?');
         foreach (Permissions::getRequiredPermissionsForScript($pageURI) as $p) {
             $cacheKey = sprintf('apppermDesc%s', $p);
             if (($desc = $fileCache->get($cacheKey)) === false) {
                 if ($db === null) {
                     $db = ConnectionFactory::getConnection();
                 }
                 $ps->clearParams();
                 $ps->setString($p);
                 if (($row = $db->fetchObject($db->executeQuery($ps), true)) !== false) {
                     $desc = $row->description;
                 } else {
                     $desc = $p;
                 }
                 $fileCache->set($cacheKey, $desc);
             }
             echo '<li>';
             echo htmlspecialchars($desc);
             echo '</li>';
         }
         if ($db !== null) {
             $db->close();
         }
         echo '</ul>';
         if ($showMenuIfFailed) {
             include dirname(dirname(__FILE__)) . '/include/footer.include.php';
         } else {
             echo '</body></html>';
         }
         exit;
     }
 }
Пример #2
0
// by running searchgen, passing in the table name.
if (isset($command) && $command == 'loadAppuser') {
    header('Content-Type: application/json');
    $db = ConnectionFactory::getConnection();
    $appuserDAO = new AppuserDAO($db);
    $approleDAO = new ApproleDAO($db);
    $id = isset($params['id']) ? (int) trim($params['id']) : 0;
    if ($id <= 0) {
        $rows = array(Appuser::createDefault());
    } else {
        $sql = <<<EOF
select * from appuser pri where pri.id = ?
EOF;
        $ps = new PreparedStatement($sql, 0, 1);
        $ps->setInt($id);
        $rows = $appuserDAO->findWithPreparedStatement($ps);
    }
    $ps1 = new PreparedStatement(<<<EOF
select distinct r.* from appuserrole u_r inner join approle r on r.role_name = u_r.role_name where u_r.user_id = ? order by r.sort_order, r.role_name
EOF
, 0, 0);
    foreach ($rows as &$row) {
        $ps1->clearParams();
        $ps1->setInt($row->id);
        $row->roles = $id <= 0 ? array() : $approleDAO->findWithPreparedStatement($ps1);
    }
    unset($row);
    echo json_encode($rows);
    $db->close();
    exit;
}