public static function load($type_, $element_ = NULL, $group_ = NULL)
 {
     Logger::debug('main', "Abstract_Liaison_ldap_posix::load({$type_},{$element_},{$group_})");
     if (str_startswith($element_, 'static_')) {
         $element_ = substr($element_, strlen('static_'));
     }
     if (str_startswith($group_, 'static_')) {
         $group_ = substr($group_, strlen('static_'));
     }
     if ($type_ == 'UsersGroup') {
         if (is_null($element_) && is_null($group_)) {
             return self::loadAll($type_);
         } else {
             if (is_null($element_)) {
                 return self::loadElements($type_, $group_);
             } else {
                 if (is_null($group_)) {
                     return self::loadGroups($type_, $element_);
                 } else {
                     return self::loadUnique($type_, $element_, $group_);
                 }
             }
         }
     } else {
         Logger::error('main', "Abstract_Liaison_ldap_posix::load error liaison != UsersGroup not implemented");
         return NULL;
     }
     return NULL;
 }
示例#2
0
function cleanse_urls($str, $article_url)
{
    $html = SimpleHtmlDom\str_get_html($str);
    foreach ($html->find('a') as $element) {
        // Fix cross posts, especially those from LMMSChallenge facebook
        if (!$element->find('img') && is_feed_image($element)) {
            $element->innertext = '<img class="img-thumbnail fb-thumb" src="' . $element->href . '"/>';
            $element->href = $article_url;
        }
        // Fix unnecessary facebook redirects
        $pos = strpos(strtolower($element->href), '.php?u=http%3a%2f%2f') + strpos(strtolower($element->href), '.php?u=https%3a%2f%2f');
        if ($pos) {
            // Remove js callbacks
            $element->onmouseover = '';
            $element->onclick = '';
            // Strip out the facebook params
            $href = explode('&', $element->href)[0];
            // Isolate and decode the proper url
            $element->href = urldecode(substr($href, $pos + 7));
        }
        // Fix relative facebook URLs
        if (str_startswith($element->href, '/')) {
            $element->href = 'https://www.facebook.com' . $element->href;
        }
    }
    foreach ($html->find('img') as $img) {
        $img->class = ($img->class ? $img->class . ' ' : '') . 'img-thumbnail fb-thumb';
    }
    return $html->save();
}
 public function match($user_)
 {
     switch ($this->type) {
         case 'equal':
             return $user_->getAttribute($this->attribute) == $this->value;
             break;
         case 'not_equal':
             return !($user_->getAttribute($this->attribute) == $this->value);
             break;
         case 'contains':
             return strstr($user_->getAttribute($this->attribute), $this->value) !== false;
             break;
         case 'not_contains':
             return !(strstr($user_->getAttribute($this->attribute), $this->value) !== false);
             break;
         case 'startswith':
             return str_startswith($user_->getAttribute($this->attribute), $this->value);
             break;
         case 'not_startswith':
             return !str_startswith($user_->getAttribute($this->attribute), $this->value);
             break;
         case 'endswith':
             return str_endswith($user_->getAttribute($this->attribute), $this->value);
             break;
         case 'not_endswith':
             return !str_endswith($user_->getAttribute($this->attribute), $this->value);
             break;
     }
     Logger::error('main', 'UserGroup_Rule::match type (=' . $this->type . ') not matched');
     return false;
 }
示例#4
0
function str_crop($string, $start, $end, $ignore_case = FALSE)
{
    if (str_startswith($string, $start, $ignore_case)) {
        $string = substr($string, strlen($start));
    }
    if (str_endswith($string, $end, $ignore_case)) {
        $string = substr($string, 0, strlen($string) - strlen($end));
    }
    return $string;
}
示例#5
0
文件: views.php 项目: kmklr72/lmms.io
function homePage()
{
    global $app;
    $screenshots = [];
    $ss_dir = 'img/screenshots/';
    $files = scandir($ss_dir);
    foreach ($files as $file) {
        if (str_startswith($file, 'ss_', true) && str_endswith($file, '.png', true)) {
            $screenshots[] = ['title' => humanize_title($file), 'path' => '/' . $ss_dir . $file, 'th_path' => '/' . $ss_dir . 'th_' . $file];
        }
    }
    return $app['twig']->render('home.twig', ['screenshots' => $screenshots]);
}
示例#6
0
 public function import($id_)
 {
     if (is_base64url($id_)) {
         $id_ = base64url_decode($id_);
     }
     Logger::debug('main', 'UserGroupDB::import(' . $id_ . ')');
     foreach ($this->instance_type as $key => $value) {
         if (str_startswith($id_, $key . '_')) {
             return $value->import(substr($id_, strlen($key) + 1));
         }
     }
     return NULL;
     // not found
 }
示例#7
0
 /**
  * Checks if this item is the currently displayed page, i.e. should be
  * displayed as active item in the menu.
  *
  * @return bool
  */
 public function isActive()
 {
     $req_uri = $_SERVER["REQUEST_URI"];
     if ($this->url == '/') {
         return $this->url == $req_uri;
     }
     if (str_startswith($req_uri, $this->url)) {
         return true;
     } elseif ($this->children) {
         foreach ($this->children as $child) {
             if (str_startswith($req_uri, $child[2])) {
                 return true;
             }
         }
     }
     return false;
 }
示例#8
0
<?php

session_start();
if (isset($_SESSION["username"])) {
    return;
}
require_once __DIR__ . "/utils.php";
$this_url = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
if (!isset($_GET["casticket"])) {
    header("Location: https://cas.iu.edu/cas/login?cassvc=IU&casurl=" . urlencode($this_url));
    exit;
}
$response_url = "https://cas.iu.edu/cas/validate?cassvc=IU&casurl=" . urlencode($this_url) . "&casticket=" . urlencode($_GET["casticket"]);
$cas_response = file_get_contents($response_url);
if (str_startswith($cas_response, "no")) {
    http_response_code(403);
    echo "Access denied.";
    exit;
}
$username = explode("\r\n", $cas_response)[1];
$_SESSION["username"] = $username;
示例#9
0
文件: net.php 项目: tapiau/muyo
 /**
  * @param string $string
  * @return array
  */
 function http_accept_decode($string)
 {
     return array_chain(explode(',', $string), array_map_val_dg(str_explode_dg(';')), array_map_val_dg(function ($pair) {
         if (1 === count($pair)) {
             $pair[] = 1.0;
         } else {
             debug_enforce(str_startswith($pair[1], 'q='));
             $pair[1] = floatval(str_find_after($pair[1], 'q='));
         }
         return $pair;
     }));
 }
示例#10
0
function show_manage($id)
{
    global $schedules;
    $prefs = Preferences::getInstance();
    if (!$prefs) {
        die_error('get Preferences failed', __FILE__, __LINE__);
    }
    $userGroupDB = UserGroupDB::getInstance();
    $group = $userGroupDB->import($id);
    if (!is_object($group)) {
        die_error(_('Failed to load usergroup'));
    }
    $usergroupdb_rw = $userGroupDB->isWriteable();
    $policy = $group->getPolicy();
    $policy_rule_enable = 0;
    $policy_rules_disable = 0;
    foreach ($policy as $key => $value) {
        if ($value === true) {
            $policy_rule_enable++;
        } else {
            $policy_rules_disable++;
        }
    }
    $buffer = $prefs_policy = $prefs->get('general', 'policy');
    $default_policy = $prefs_policy['default_policy'];
    if (!is_object($group)) {
        die_error('Group "' . $id . '" is not OK', __FILE__, __LINE__);
    }
    if ($group->published) {
        $status = '<span class="msg_ok">' . _('Enabled') . '</span>';
        $status_change = _('Block');
        $status_change_value = 0;
    } else {
        $status = '<span class="msg_error">' . _('Blocked') . '</span>';
        $status_change = _('Enable');
        $status_change_value = 1;
    }
    $userDB = UserDB::getInstance();
    $applicationsGroupDB = ApplicationsGroupDB::getInstance();
    if ($group->isDefault() == false) {
        $users = $group->usersLogin();
        sort($users);
        $has_users = count($users) > 0;
        if ($usergroupdb_rw) {
            $usersList = new UsersList($_REQUEST);
            $users_all = $usersList->search();
            $search_form = $usersList->getForm(array('action' => 'manage', 'id' => $id, 'search_user' => true));
            if (is_null($users_all)) {
                $users_all = array();
            }
            $users_available = array();
            foreach ($users_all as $user) {
                $found = false;
                foreach ($users as $user2) {
                    if ($user2 == $user->getAttribute('login')) {
                        $found = true;
                    }
                }
                if (!$found) {
                    $users_available[] = $user->getAttribute('login');
                }
            }
        } else {
            $users_available = array();
            $users_all = array();
            foreach ($users as $a_login) {
                $users_all[] = $userDB->import($a_login);
            }
            usort($users_all, "user_cmp");
        }
    } else {
        $users = array();
        $users_available = array();
        $users_all = array();
        $search_form = null;
    }
    // Default usergroup
    $is_default_group = $prefs->get('general', 'user_default_group') == $id;
    // Publications
    $groups_apps = array();
    foreach (Abstract_Liaison::load('UsersGroupApplicationsGroup', $id, NULL) as $group_a) {
        $obj = $applicationsGroupDB->import($group_a->group);
        if (is_object($obj)) {
            $groups_apps[] = $obj;
        }
    }
    $groups_apps_all = $applicationsGroupDB->getList();
    $groups_apps_available = array();
    foreach ($groups_apps_all as $group_apps) {
        if (!in_array($group_apps, $groups_apps)) {
            $groups_apps_available[] = $group_apps;
        }
    }
    $can_manage_usersgroups = isAuthorized('manageUsersGroups');
    $can_manage_publications = isAuthorized('managePublications');
    $can_manage_sharedfolders = isAuthorized('manageServers');
    $prefs_to_get_for_a_group = array('session_settings_defaults', 'remote_desktop_settings', 'remote_applications_settings');
    $prefs_of_a_group = array();
    $unuse_settings = array();
    $session_prefs = array();
    foreach ($prefs_to_get_for_a_group as $prefs_to_get_for_a_group_value) {
        $prefs_of_a_group[$prefs_to_get_for_a_group_value] = array();
        $unuse_settings[$prefs_to_get_for_a_group_value] = array();
        $session_prefs[$prefs_to_get_for_a_group_value] = $prefs->getElements('general', $prefs_to_get_for_a_group_value);
        $prefs_of_a_group_unsort = Abstract_UserGroup_Preferences::loadByUserGroupId($group->getUniqueID(), 'general', $prefs_to_get_for_a_group_value);
        foreach ($session_prefs[$prefs_to_get_for_a_group_value] as $k4 => $v4) {
            // we should use the ones from the group ($prefs_of_a_group_unsort) but we can display then if they are in $session_prefs
            if (array_key_exists($k4, $prefs_of_a_group_unsort)) {
                $prefs_of_a_group[$prefs_to_get_for_a_group_value][$k4] = $prefs_of_a_group_unsort[$k4];
            } else {
                $unuse_settings[$prefs_to_get_for_a_group_value][$k4] = $v4;
            }
        }
    }
    page_header();
    echo '<div id="users_div">';
    echo '<h1><a href="?">' . _('User groups management') . '</a> - ' . $group->name . '</h1>';
    echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="5">';
    echo '<tr class="title">';
    echo '<th>' . _('Description') . '</th>';
    echo '<th>' . _('Status') . '</th>';
    echo '</tr>';
    echo '<tr class="content1">';
    echo '<td>' . $group->description . '</td>';
    echo '<td>' . $status . '</td>';
    echo '</tr>';
    echo '</table>';
    if ($can_manage_usersgroups) {
        echo '<div>';
        echo '<h2>' . _('Settings') . '</h1>';
        if ($group->type == 'static' and $can_manage_usersgroups and $usergroupdb_rw) {
            echo '<form action="actions.php" method="post">';
            if ($is_default_group) {
                echo '<input type="submit" value="' . _('Remove from default') . '"/>';
                echo '<input type="hidden" name="action" value="unset_default" />';
            } else {
                echo '<input type="submit" value="' . _('Define as default') . '"/>';
                echo '<input type="hidden" name="action" value="set_default" />';
            }
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="id" value="' . $group->getUniqueID() . '" />';
            echo '</form>';
            echo '<br/>';
        }
        if ($usergroupdb_rw || $group->type != 'static') {
            echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this group?') . '\');">';
            echo '<input type="submit" value="' . _('Delete this group') . '"/>';
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="action" value="del" />';
            echo '<input type="hidden" name="checked_groups[]" value="' . $id . '" />';
            echo '</form>';
            echo '<br/>';
            echo '<form action="actions.php" method="post">';
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="action" value="modify" />';
            echo '<input type="hidden" name="id" value="' . $id . '" />';
            echo '<input type="hidden" name="published" value="' . $status_change_value . '" />';
            echo '<input type="submit" value="' . $status_change . '"/>';
            echo '</form>';
            echo '<br/>';
            echo '<form action="actions.php" method="post">';
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="action" value="modify" />';
            echo '<input type="hidden" name="id" value="' . $id . '" />';
            echo '<input type="text" name="name_group"  value="' . $group->name . '" size="50" /> ';
            echo '<input type="submit" value="' . _('Update the name') . '"/>';
            echo '</form>';
            echo '<br/>';
            echo '<form action="actions.php" method="post">';
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="action" value="modify" />';
            echo '<input type="hidden" name="id" value="' . $id . '" />';
            echo '<input type="text" name="description"  value="' . $group->description . '" size="50" /> ';
            echo '<input type="submit" value="' . _('Update the description') . '"/>';
            echo '</form>';
        }
        if ($group->type == 'dynamiccached') {
            echo '<br />';
            echo '<form action="actions.php" method="post">';
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="action" value="modify" />';
            echo '<input type="hidden" name="id" value="' . $id . '" />';
            echo ' <select name="schedule">';
            foreach ($schedules as $interval => $text) {
                echo '<option value="' . $interval . '"';
                if ($group->schedule == $interval) {
                    echo ' selected="selected"';
                }
                echo '>' . $text . '</option>';
            }
            echo '</select>';
            echo '<input type="submit" value="' . _('Update the schedule') . '"/>';
            echo '</form>';
        }
        echo '</div>';
        echo '<br/>';
    }
    if (str_startswith($group->type, 'dynamic')) {
        echo '<div>';
        echo '<h2>' . _('Rules') . '</h1>';
        if ($can_manage_usersgroups) {
            echo '<form action="actions.php" method="post">';
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="action" value="modify_rules" />';
            echo '<input type="hidden" name="id" value="' . $id . '" />';
        }
        echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="3">';
        echo '<tr class="content1">';
        echo '<th>' . _('Validation type') . '</th>';
        echo '<td><input type="radio" name="validation_type" value="and"';
        if ($group->validation_type == 'and') {
            echo ' checked="checked"';
        }
        echo ' /> ' . _('All') . ' <input type="radio" name="validation_type" value="or"';
        if ($group->validation_type == 'or') {
            echo ' checked="checked"';
        }
        echo ' /> ' . _('At least one') . '</td>';
        echo '</tr>';
        echo '<tr class="content2">';
        echo '<th>' . _('Filters') . '</th>';
        echo '<td>';
        $i = 0;
        $filter_attributes = $userDB->getAttributesList();
        foreach ($filter_attributes as $key1 => $value1) {
            if ($value1 == 'password') {
                unset($filter_attributes[$key1]);
            }
        }
        $filter_types = UserGroup_Rule::$types;
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        $i = 0;
        foreach ($group->rules as $rule) {
            echo '<tr>';
            echo '<td><select name="rules[' . $i . '][attribute]">';
            foreach ($filter_attributes as $filter_attribute) {
                echo '<option value="' . $filter_attribute . '"';
                if ($rule->attribute == $filter_attribute) {
                    echo ' selected="selected"';
                }
                echo '>' . $filter_attribute . '</option>';
            }
            echo '</select></td>';
            echo '<td><select name="rules[' . $i . '][type]">';
            foreach ($filter_types as $filter_type) {
                echo '<option value="' . $filter_type . '"';
                if ($rule->type == $filter_type) {
                    echo ' selected="selected"';
                }
                echo '>' . $filter_type . '</option>';
            }
            echo '</select></td>';
            echo '<td><input type="text" name="rules[' . $i . '][value]" value="' . $rule->value . '" /></td>';
            if ($can_manage_usersgroups) {
                echo '<td>';
                echo '<input';
                if ($i == 0 && count($group->rules) == 1 || $i == count($group->rules)) {
                    echo ' style="display: none;"';
                }
                echo ' type="button" onclick="del_field(this.parentNode.parentNode); return false;" value="-" />';
                echo '<input';
                if ($i + 1 != count($group->rules)) {
                    echo ' style="display: none;"';
                }
                echo ' type="button" onclick="add_field(this.parentNode.parentNode); return false;" value="+" />';
                echo '</td>';
            }
            echo '</tr>';
            $i++;
        }
        echo '</table>';
        echo '</td>';
        echo '</tr>';
        echo '</table>';
        echo '<br />';
        if ($can_manage_usersgroups) {
            echo '<input type="submit" value="' . _('Update rules') . '" />';
            echo '</form>';
        }
        echo '</div>';
        echo '<br />';
    }
    // Users list
    if (count($users_all) > 0 || count($users) > 0 || $group->isDefault()) {
        echo '<div>';
        echo '<h2>' . _('List of users in this group') . '</h2>';
        if ($group->isDefault()) {
            echo _('All available users are in this group.');
        } else {
            echo '<table border="0" cellspacing="1" cellpadding="3">';
            if (count($users) > 0) {
                foreach ($users as $user) {
                    echo '<tr>';
                    echo '<td><a href="users.php?action=manage&id=' . $user . '">' . $user . '</td>';
                    echo '<td>';
                    if ($usergroupdb_rw && $group->type == 'static' && !$group->isDefault() and $can_manage_usersgroups) {
                        echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this user?') . '\');">';
                        echo '<input type="hidden" name="action" value="del" />';
                        echo '<input type="hidden" name="name" value="User_UserGroup" />';
                        echo '<input type="hidden" name="group" value="' . $id . '" />';
                        echo '<input type="hidden" name="element" value="' . $user . '" />';
                        echo '<input type="submit" value="' . _('Delete from this group') . '" />';
                        echo '</form>';
                        echo '</td>';
                    }
                    echo '</tr>';
                }
            }
            if (count($users_available) > 0 && $usergroupdb_rw && $group->type == 'static' and $can_manage_usersgroups) {
                echo '<tr><form action="actions.php" method="post"><td>';
                echo '<input type="hidden" name="action" value="add" />';
                echo '<input type="hidden" name="name" value="User_UserGroup" />';
                echo '<input type="hidden" name="group" value="' . $id . '" />';
                echo '<select name="element">';
                foreach ($users_available as $user) {
                    echo '<option value="' . $user . '" >' . $user . '</option>';
                }
                echo '</select>';
                echo '</td><td><input type="submit" value="' . _('Add to this group') . '" /></td>';
                echo '</form></tr>';
            }
            echo '</table>';
            if ($usergroupdb_rw && $group->type == 'static' and $can_manage_usersgroups) {
                echo '<br/>';
                echo $search_form;
            }
            echo '</div>';
            echo '<br/>';
        }
    }
    // Publications part
    if (count($groups_apps_all) > 0) {
        echo '<div>';
        echo '<h2>' . _('List of publications for this group') . '</h1>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        if (count($groups_apps) > 0) {
            foreach ($groups_apps as $groups_app) {
                echo '<tr>';
                echo '<td><a href="appsgroup.php?action=manage&id=' . $groups_app->id . '">' . $groups_app->name . '</td>';
                if ($can_manage_publications) {
                    echo '<td>';
                    echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this publication?') . '\');">';
                    echo '<input type="hidden" name="action" value="del" />';
                    echo '<input type="hidden" name="name" value="Publication" />';
                    echo '<input type="hidden" name="group_u" value="' . $id . '" />';
                    echo '<input type="hidden" name="group_a" value="' . $groups_app->id . '" />';
                    echo '<input type="submit" value="' . _('Delete this publication') . '" />';
                    echo '</form>';
                    echo '</td>';
                }
                echo '</tr>';
            }
        }
        if (count($groups_apps_available) > 0 and $can_manage_publications) {
            echo '<tr><form action="actions.php" method="post"><td>';
            echo '<input type="hidden" name="action" value="add" />';
            echo '<input type="hidden" name="name" value="Publication" />';
            echo '<input type="hidden" name="group_u" value="' . $id . '" />';
            echo '<select name="group_a">';
            foreach ($groups_apps_available as $group_apps) {
                echo '<option value="' . $group_apps->id . '" >' . $group_apps->name . '</option>';
            }
            echo '</select>';
            echo '</td><td><input type="submit" value="' . _('Add this publication') . '" /></td>';
            echo '</form></tr>';
        }
        echo '</table>';
        echo '</div>';
    }
    // Policy of this group
    echo '<div>';
    echo '<h2>' . _('Policy of this group') . '</h2>';
    echo '<table border="0" cellspacing="1" cellpadding="3">';
    foreach ($policy as $key => $value) {
        if ($value === false) {
            continue;
        }
        $extends_from_default = in_array($key, $default_policy);
        $buffer = $extends_from_default === true ? ' (' . _('extend from default') . ')' : '';
        echo '<tr>';
        echo '<td>' . $key . ' ' . $buffer . '</td>';
        if ($can_manage_usersgroups && !$extends_from_default) {
            echo '<td>';
            echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this rule?') . '\');">';
            echo '<input type="hidden" name="name" value="UserGroup_PolicyRule" />';
            echo '<input type="hidden" name="action" value="del" />';
            echo '<input type="hidden" name="id" value="' . $group->getUniqueID() . '" />';
            echo '<input type="hidden" name="element" value="' . $key . '" />';
            echo '<input type="submit" value="' . _('Delete this rule') . '" />';
            echo '</form>';
            echo '</td>';
        }
        echo '</tr>';
    }
    if ($can_manage_usersgroups && count($policy_rules_disable) > 0 && array_search(false, $policy) !== false) {
        echo '<tr><form action="actions.php" method="post"><td>';
        echo '<input type="hidden" name="name" value="UserGroup_PolicyRule" />';
        echo '<input type="hidden" name="action" value="add" />';
        echo '<input type="hidden" name="id" value="' . $group->getUniqueID() . '" />';
        echo '<select name="element">';
        foreach ($policy as $key => $value) {
            if ($value === true) {
                continue;
            }
            echo '<option value="' . $key . '" >' . $key . '</option>';
        }
        echo '</select>';
        echo '</td><td><input type="submit" value="' . _('Add this rule') . '" /></td>';
        echo '</form></tr>';
    }
    echo '</table>';
    echo '</div>';
    echo '<br/>';
    if (Preferences::moduleIsEnabled('SharedFolderDB')) {
        $sharedfolderdb = SharedFolderDB::getInstance();
        $all_sharedfolders = $sharedfolderdb->getList();
        if (count($all_sharedfolders) > 0) {
            $available_sharedfolders = array();
            $used_sharedfolders = $sharedfolderdb->importFromUsergroup($group->getUniqueID());
            foreach ($all_sharedfolders as $sharedfolder) {
                if (in_array($sharedfolder->id, array_keys($used_sharedfolders))) {
                    continue;
                }
                $available_sharedfolders[] = $sharedfolder;
            }
            echo '<br />';
            echo '<div>';
            echo '<h2>' . _('Shared folders') . '</h1>';
            echo '<table border="0" cellspacing="1" cellpadding="3">';
            foreach ($used_sharedfolders as $sharedfolder) {
                echo '<tr>';
                echo '<td><a href="sharedfolders.php?action=manage&amp;id=' . $sharedfolder->id . '">' . $sharedfolder->name . '</a></td>';
                if ($can_manage_sharedfolders) {
                    echo '<td><form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this shared folder access?') . '\');">';
                    echo '<input type="hidden" name="name" value="SharedFolder_ACL" />';
                    echo '<input type="hidden" name="action" value="del" />';
                    echo '<input type="hidden" name="sharedfolder_id" value="' . $sharedfolder->id . '" />';
                    echo '<input type="hidden" name="usergroup_id" value="' . $group->getUniqueID() . '" />';
                    echo '<input type="submit" value="' . _('Delete access to this shared folder') . '" />';
                    echo '</form></td>';
                }
                echo '</tr>';
            }
            if (count($available_sharedfolders) > 0 && $can_manage_sharedfolders) {
                echo '<tr><form action="actions.php" method="post"><td>';
                echo '<input type="hidden" name="name" value="SharedFolder_ACL" />';
                echo '<input type="hidden" name="action" value="add" />';
                echo '<input type="hidden" name="usergroup_id" value="' . $group->getUniqueID() . '" />';
                echo '<select name="sharedfolder_id">';
                foreach ($available_sharedfolders as $sharedfolder) {
                    echo '<option value="' . $sharedfolder->id . '" >' . $sharedfolder->name . '</option>';
                }
                echo '</select>';
                echo '</td><td><input type="submit" value="' . _('Add access to this shared folder') . '" /></td>';
                echo '</form></tr>';
            }
            echo '</table>';
            echo '</div>';
        }
        echo '<br />';
    }
    echo '<div>';
    // Session settings configuration
    echo '<h2>';
    echo _('Session settings configuration');
    echo '</h2>';
    if ($prefs_of_a_group != array()) {
        foreach ($prefs_of_a_group as $container => $prefs_of_a_group_value) {
            echo '<fieldset class="prefssessionusergroup">';
            echo '<legend>' . $prefs->getPrettyName($container) . '</legend>';
            echo '<form action="actions.php" method="post">';
            $key_name = 'general';
            echo '<input type="hidden" name="container" value="' . $container . '" />';
            // from admin/functions.inc.php
            $color = 0;
            if (count($prefs_of_a_group_value) != 0) {
                echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="3" style="margin-bottom: 10px;">';
                // TODO
                echo '<tr  class="title">';
                echo '<th>' . _('Name') . '</th>';
                echo '<th>' . _('Default value') . '</th>';
                echo '<th>' . _('Value') . '</th>';
                echo '<th>' . _('Action') . '</th>';
                echo '<tr>';
                foreach ($prefs_of_a_group_value as $element_key => $usersgroup_preferences) {
                    $config_element = $usersgroup_preferences->toConfigElement();
                    echo '<tr class="content' . ($color % 2 + 1) . '">';
                    echo '<td style="width: 250px;">';
                    echo '<span onmouseover="showInfoBulle(\'' . str_replace("'", "&rsquo;", $config_element->description_detailed) . '\'); return false;" onmouseout="hideInfoBulle(); return false;">' . $config_element->label . '</span>';
                    echo '<td>';
                    $default_element = $session_prefs[$container][$config_element->id];
                    $default_element->setFormSeparator('NaN');
                    // it must be different of ___
                    $default_element->setPath(array('key_name' => $key_name, 'container' => $container, 'element_id' => $config_element->id));
                    echo $default_element->toHTML(true);
                    echo '</td>';
                    echo '</td>';
                    echo '<td style="padding: 3px;">';
                    print_element($key_name, $container, $element_key, $config_element);
                    echo '</td>';
                    echo '<td>';
                    echo '<input type="button" value="' . _('Remove this overriden setting') . '" onclick="usergroup_settings_remove(\'' . $group->getUniqueID() . '\',\'' . $container . '\',\'' . $config_element->id . '\'); return false;"/>';
                    echo '</td>';
                    echo '</tr>';
                    $color++;
                }
                // end from
                echo '<tr class="content' . ($color % 2 + 1) . '">';
                echo '<td colspan="3"></td>';
                echo '<td>';
                echo '<input type="hidden" name="name" value="UserGroup_settings" />';
                echo '<input type="hidden" name="container" value="' . $container . '" />';
                echo '<input type="hidden" name="unique_id" value="' . $group->getUniqueID() . '" />';
                echo '<input type="hidden" name="action" value="modify" />';
                echo '<input type="submit" value="' . _('Save settings') . '" />';
                echo '</td>';
                echo '</tr>';
                echo '</table>';
                echo '</form>';
            }
            if ($unuse_settings[$container] != array()) {
                echo '<form action="actions.php" method="post">';
                echo '<input type="hidden" name="name" value="UserGroup_settings" />';
                echo '<input type="hidden" name="container" value="' . $container . '" />';
                echo '<input type="hidden" name="unique_id" value="' . $group->getUniqueID() . '" />';
                echo '<input type="hidden" name="action" value="add" />';
                echo '<select name="element_id">';
                foreach ($unuse_settings[$container] as $setting_name => $setting_content) {
                    echo '<option value="' . $setting_name . '" >' . $setting_content->label . '</option>';
                }
                echo '</select>';
                echo ' ';
                echo '<input type="submit" value="' . _('Add this setting') . '" />';
                echo '</form>';
            }
            echo '</fieldset>';
        }
    }
    echo '</div>';
    // Session settings configuration
    echo "\n\n\n";
    echo '</div>';
    page_footer();
    die;
}
示例#11
0
/**
    Check if user is allowed to access $file in $directory
*/
function get_show_item($directory, $file)
{
    // no relative paths are allowed in directories
    if (preg_match("/\\.\\./", $directory)) {
        return false;
    }
    if (isset($file)) {
        // file name must not contain any path separators
        if (preg_match("/[\\/\\\\]/", $file)) {
            return false;
        }
        // dont display own and parent directory
        if ($file == "." || $file == "..") {
            return false;
        }
        // determine full path to the file
        $full_path = get_abs_item($directory, $file);
        _debug("full_path: {$full_path}");
        if (!str_startswith($full_path, path_f())) {
            return false;
        }
    }
    // check if user is allowed to acces shidden files
    global $show_hidden;
    if (!$show_hidden) {
        if ($file[0] == '.') {
            return false;
        }
        // no part of the path may be hidden
        $directory_parts = explode("/", $directory);
        foreach ($directory_parts as $directory_part) {
            if ($directory_part[0] == '.') {
                return false;
            }
        }
    }
    if (matches_noaccess_pattern($file)) {
        return false;
    }
    return true;
}
示例#12
0
 public function get_groups_including_user_from_list($users_groups_id_, $user_)
 {
     Logger::debug('main', 'UserGroupDB::get_groups_including_user_from_list([' . implode(', ', $users_groups_id_) . '], ' . $user_->getAttribute('login') . ')');
     $groups_by_type = array();
     foreach ($users_groups_id_ as $users_group_id) {
         foreach ($this->instance_type as $key => $value) {
             if (str_startswith($users_group_id, $key . '_')) {
                 if (!array_key_exists($key, $groups_by_type)) {
                     $groups_by_type[$key] = array();
                 }
                 array_push($groups_by_type[$key], substr($users_group_id, strlen($key) + 1));
                 break;
             }
         }
     }
     $result = array();
     foreach ($this->instance_type as $key => $value) {
         if (!array_key_exists($key, $groups_by_type)) {
             continue;
         }
         $groups = $value->get_groups_including_user_from_list($groups_by_type[$key], $user_);
         foreach ($groups as $group_id => $group) {
             $result[$group->getUniqueID()] = $group;
         }
     }
     // default users group
     $prefs = Preferences::getInstance();
     $user_default_group = $prefs->get('general', 'user_default_group');
     if (!is_null($user_default_group) && !in_array($user_default_group, array('-1', ''))) {
         if (!array_key_exists($user_default_group, $result)) {
             $group = $this->import($user_default_group);
             if ($group) {
                 $result[$group->getUniqueID()] = $group;
             }
         }
     }
     return $result;
 }
示例#13
0
文件: functions.php 项目: Simo22/smt2
/** 
 * Count files in a dir. This function skip directories, and it is not recursive.
 * By now it is only used to check the cache logs. 
 * @param   string  $dir    the directory to read files from
 * @return  int             Number of files
 */
function count_dir_files($dir)
{
    $count = 0;
    if ($handle = opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if (!str_startswith($file, ".") && is_file($dir . '/' . $file)) {
                $count++;
            }
        }
        closedir($handle);
    }
    return $count;
}
示例#14
0
 public function get_groups_including_user_from_list($groups_id_, $user_)
 {
     $liasons = Abstract_Liaison::load('UsersGroup', $user_->getAttribute('login'), NULL);
     $groups_id2 = array();
     foreach ($liasons as $useless => $liason) {
         if (!str_startswith($liason->group, 'static_')) {
             continue;
         }
         $group_id = substr($liason->group, strlen('static_'));
         if (!in_array($group_id, $groups_id_)) {
             continue;
         }
         array_push($groups_id2, $group_id);
     }
     return $this->imports($groups_id2);
 }
 public static function suffix2domain($suffix_, $separator = 'dc')
 {
     $buf = explode(',', $suffix_);
     if (!count($buf)) {
         return;
     }
     $build = array();
     foreach ($buf as $s) {
         if (!str_startswith($s, $separator . '=')) {
             return;
         }
         $build[] = strtoupper(substr($s, strlen($separator) + 1));
     }
     $str = implode('.', $build);
     return $str;
 }
示例#16
0
 private static function check_pref_change($diff_, $pattern_)
 {
     foreach ($diff_ as $k => $v) {
         if (str_startswith($k, $pattern_)) {
             return true;
         }
     }
     return false;
 }
示例#17
0
 /**
  * @param string $backupFile
  * @param string $path
  * @return bool
  */
 function tar_contains($backupFile, $path)
 {
     $output = tar_ls($backupFile);
     return array_some($output, function ($line) use($path) {
         return str_startswith($line, $path);
     });
 }
示例#18
0
文件: string.php 项目: tapiau/muyo
 /**
  * @param string $string
  * @param string $substring
  * @return int
  */
 function str_count($string, $substring)
 {
     $strlen = strlen($string);
     $count = 0;
     for ($i = 0; $i < $strlen; $i++) {
         if (str_startswith(str_from($string, $i), $substring)) {
             $count++;
         }
     }
     return $count;
 }
示例#19
0
function show_manage($id)
{
    global $schedules;
    $group = $_SESSION['service']->users_group_info($id);
    if (!is_object($group)) {
        die_error(_('Failed to load User Group'));
    }
    $usergroupdb_rw = usergroupdb_is_writable();
    $policy = $group->getAttribute('policy');
    $policy_rule_enable = 0;
    $policy_rules_disable = 0;
    foreach ($policy as $key => $value) {
        if ($value === true) {
            $policy_rule_enable++;
        } else {
            $policy_rules_disable++;
        }
    }
    $default_policy = $group->getAttribute('default_policy');
    if ($group->published) {
        $status = '<span class="msg_ok">' . _('Enabled') . '</span>';
        $status_change = _('Block');
        $status_change_value = 0;
    } else {
        $status = '<span class="msg_error">' . _('Blocked') . '</span>';
        $status_change = _('Enable');
        $status_change_value = 1;
    }
    if ($group->isDefault() == false) {
        $users = array();
        if ($group->hasAttribute('users')) {
            $users = $group->getAttribute('users');
        }
        $users_partial_list = $group->getAttribute('users_partial_list');
        $usersList = new UsersList($_REQUEST);
        if ($users_partial_list) {
            if ($usersList->is_empty_filter()) {
                $usersList->set_external_result($users, true);
            } else {
                $users2 = $usersList->search($id);
                if (is_null($users2)) {
                    die_error(_('Error while requesting users'), __FILE__, __LINE__);
                }
                $users = array();
                foreach ($users2 as $user) {
                    $users[$user->getAttribute('login')] = $user->getAttribute('displayname');
                }
            }
        }
        asort($users);
        $has_users = count($users) > 0;
        if ($usergroupdb_rw) {
            $users_all = $usersList->search();
            if (is_null($users_all)) {
                $users_all = array();
            }
            $users_available = array();
            foreach ($users_all as $user) {
                if (!array_key_exists($user->getAttribute('login'), $users)) {
                    $users_available[] = $user->getAttribute('login');
                }
            }
        } else {
            $users_available = array();
            $users_all = $users;
            uasort($users_all, "user_cmp");
        }
        $search_form = $usersList->getForm();
    } else {
        $users = array();
        $users_available = array();
        $users_all = array();
        $search_form = null;
    }
    // Default usergroup
    $is_default_group = $group->isDefault();
    // Publications
    $groups_apps = array();
    if ($group->hasAttribute('applicationsgroups')) {
        $groups_apps = $group->getAttribute('applicationsgroups');
    }
    $groups_apps_all = $_SESSION['service']->applications_groups_list();
    $groups_apps_available = array();
    foreach ($groups_apps_all as $group_apps) {
        if (!array_key_exists($group_apps->id, $groups_apps)) {
            $groups_apps_available[] = $group_apps;
        }
    }
    // Scripts
    $groups_scripts_all = $_SESSION['service']->scripts_groups_list($id);
    $all_scripts = $_SESSION['service']->scripts_list();
    $scripts_available = array();
    foreach ($all_scripts as $script) {
        if (!array_key_exists($script->id, $groups_scripts_all)) {
            $scripts_available[] = $script;
        }
    }
    // Servers publications
    $servers_groups_list = $_SESSION['service']->servers_groups_list();
    $servers_groups_published = array();
    if ($group->hasAttribute('serversgroups')) {
        $servers_groups_published = $group->getAttribute('serversgroups');
    }
    $can_manage_scripts = isAuthorized('manageScripts');
    $can_manage_usersgroups = isAuthorized('manageUsersGroups');
    $can_manage_publications = isAuthorized('managePublications');
    $can_manage_sharedfolders = isAuthorized('manageServers');
    $prefs_of_a_group = array();
    $unuse_settings = array();
    $session_prefs = array();
    if ($group->hasAttribute('settings_default')) {
        $prefs = new Preferences_admin(null, false);
        $categs = $group->getAttribute('settings_default');
        $categs2 = array();
        if ($group->hasAttribute('settings')) {
            $categs2 = $group->getAttribute('settings');
        }
        foreach ($categs as $categ => $settings) {
            $session_prefs[$categ] = array();
            $prefs_of_a_group[$categ] = array();
            $unuse_settings[$categ] = array();
            foreach ($settings as $setting_id => $setting_attributes) {
                $p = $prefs->load_element($setting_attributes, 'general_' . $categ);
                $session_prefs[$categ][$setting_id] = $p;
                if (array_key_exists($categ, $categs2) && array_key_exists($setting_id, $categs2[$categ])) {
                    $p2 = clone $p;
                    $p2->content = $categs2[$categ][$setting_id];
                    $prefs_of_a_group[$categ][$setting_id] = $p2;
                } else {
                    $unuse_settings[$categ][$setting_id] = $p;
                }
            }
        }
    }
    page_header();
    echo '<div id="users_div">';
    echo '<h1><a href="?">' . _('User Group Management') . '</a> - ' . $group->name . '</h1>';
    echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="5">';
    echo '<tr class="title">';
    echo '<th>' . _('Description') . '</th>';
    echo '<th>' . _('Status') . '</th>';
    echo '</tr>';
    echo '<tr class="content1">';
    echo '<td>' . $group->description . '</td>';
    echo '<td>' . $status . '</td>';
    echo '</tr>';
    echo '</table>';
    if ($can_manage_usersgroups) {
        echo '<div>';
        echo '<h2>' . _('Settings') . '</h1>';
        if ($group->type == 'static' and $can_manage_usersgroups and $usergroupdb_rw) {
            echo '<form action="actions.php" method="post">';
            if ($is_default_group) {
                echo '<input type="submit" value="' . _('Remove from default') . '"/>';
                echo '<input type="hidden" name="action" value="unset_default" />';
            } else {
                echo '<input type="submit" value="' . _('Define as default') . '"/>';
                echo '<input type="hidden" name="action" value="set_default" />';
            }
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="id" value="' . $group->id . '" />';
            echo '</form>';
            echo '<br/>';
        }
        if ($usergroupdb_rw || $group->type != 'static') {
            echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this group?') . '\');">';
            echo '<input type="submit" value="' . _('Delete this group') . '"/>';
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="action" value="del" />';
            echo '<input type="hidden" name="checked_groups[]" value="' . $id . '" />';
            echo '</form>';
            echo '<br/>';
            echo '<form action="actions.php" method="post">';
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="action" value="modify" />';
            echo '<input type="hidden" name="id" value="' . $id . '" />';
            echo '<input type="hidden" name="published" value="' . $status_change_value . '" />';
            echo '<input type="submit" value="' . $status_change . '"/>';
            echo '</form>';
            echo '<br/>';
            echo '<form action="actions.php" method="post">';
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="action" value="modify" />';
            echo '<input type="hidden" name="id" value="' . $id . '" />';
            echo '<input type="text" name="name_group"  value="' . $group->name . '" size="50" /> ';
            echo '<input type="submit" value="' . _('Update the name') . '"/>';
            echo '</form>';
            echo '<br/>';
            echo '<form action="actions.php" method="post">';
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="action" value="modify" />';
            echo '<input type="hidden" name="id" value="' . $id . '" />';
            echo '<input type="text" name="description"  value="' . $group->description . '" size="50" /> ';
            echo '<input type="submit" value="' . _('Update the description') . '"/>';
            echo '</form>';
        }
        if ($group->type == 'dynamiccached') {
            echo '<br />';
            echo '<form action="actions.php" method="post">';
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="action" value="modify" />';
            echo '<input type="hidden" name="id" value="' . $id . '" />';
            echo ' <select name="schedule">';
            foreach ($schedules as $interval => $text) {
                echo '<option value="' . $interval . '"';
                if ($group->schedule == $interval) {
                    echo ' selected="selected"';
                }
                echo '>' . $text . '</option>';
            }
            echo '</select>';
            echo '<input type="submit" value="' . _('Update the schedule') . '"/>';
            echo '</form>';
        }
        echo '</div>';
        echo '<br/>';
    }
    if (str_startswith($group->type, 'dynamic')) {
        echo '<div>';
        echo '<h2>' . _('Rules') . '</h1>';
        if ($can_manage_usersgroups) {
            echo '<form action="actions.php" method="post">';
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="action" value="modify_rules" />';
            echo '<input type="hidden" name="id" value="' . $id . '" />';
        }
        echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="3">';
        echo '<tr class="content1">';
        echo '<th>' . _('Validation type') . '</th>';
        echo '<td><input type="radio" name="validation_type" value="and"';
        if ($group->validation_type == 'and') {
            echo ' checked="checked"';
        }
        echo ' /> ' . _('All') . ' <input type="radio" name="validation_type" value="or"';
        if ($group->validation_type == 'or') {
            echo ' checked="checked"';
        }
        echo ' /> ' . _('At least one') . '</td>';
        echo '</tr>';
        echo '<tr class="content2">';
        echo '<th>' . _('Filters') . '</th>';
        echo '<td>';
        $i = 0;
        $filter_attributes = $userDB->getAttributesList();
        foreach ($filter_attributes as $key1 => $value1) {
            if ($value1 == 'password') {
                unset($filter_attributes[$key1]);
            }
        }
        $filter_types = UserGroup_Rule::$types;
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        $i = 0;
        foreach ($group->rules as $rule) {
            echo '<tr>';
            echo '<td><select name="rules[' . $i . '][attribute]">';
            foreach ($filter_attributes as $filter_attribute) {
                echo '<option value="' . $filter_attribute . '"';
                if ($rule->attribute == $filter_attribute) {
                    echo ' selected="selected"';
                }
                echo '>' . $filter_attribute . '</option>';
            }
            echo '</select></td>';
            echo '<td><select name="rules[' . $i . '][type]">';
            foreach ($filter_types as $filter_type) {
                echo '<option value="' . $filter_type . '"';
                if ($rule->type == $filter_type) {
                    echo ' selected="selected"';
                }
                echo '>' . $filter_type . '</option>';
            }
            echo '</select></td>';
            echo '<td><input type="text" name="rules[' . $i . '][value]" value="' . $rule->value . '" /></td>';
            if ($can_manage_usersgroups) {
                echo '<td>';
                echo '<input';
                if ($i == 0 && count($group->rules) == 1 || $i == count($group->rules)) {
                    echo ' style="display: none;"';
                }
                echo ' type="button" onclick="del_field(this.parentNode.parentNode); return false;" value="-" />';
                echo '<input';
                if ($i + 1 != count($group->rules)) {
                    echo ' style="display: none;"';
                }
                echo ' type="button" onclick="add_field(this.parentNode.parentNode); return false;" value="+" />';
                echo '</td>';
            }
            echo '</tr>';
            $i++;
        }
        echo '</table>';
        echo '</td>';
        echo '</tr>';
        echo '</table>';
        echo '<br />';
        if ($can_manage_usersgroups) {
            echo '<input type="submit" value="' . _('Update rules') . '" />';
            echo '</form>';
        }
        echo '</div>';
        echo '<br />';
    }
    // User list
    if ($group->isDefault() || (count($users_all) > 0 || !$usersList->is_empty_filter() || count($users) > 0)) {
        echo '<div>';
        echo '<h2>' . _('List of users in this group') . '</h2>';
        if (!is_null($search_form)) {
            echo $search_form;
        }
        if ($group->isDefault()) {
            echo _('All available users are in this group.');
        } else {
            echo '<table border="0" cellspacing="1" cellpadding="3">';
            if (count($users) > 0) {
                foreach ($users as $user_login => $user_displayname) {
                    echo '<tr>';
                    echo '<td><a href="users.php?action=manage&id=' . $user_login . '">' . $user_login . '</td>';
                    echo '<td>';
                    if ($usergroupdb_rw && $group->type == 'static' && !$group->isDefault() and $can_manage_usersgroups) {
                        echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this user?') . '\');">';
                        echo '<input type="hidden" name="action" value="del" />';
                        echo '<input type="hidden" name="name" value="User_UserGroup" />';
                        echo '<input type="hidden" name="group" value="' . $id . '" />';
                        echo '<input type="hidden" name="element" value="' . $user_login . '" />';
                        echo '<input type="submit" value="' . _('Delete from this group') . '" />';
                        echo '</form>';
                        echo '</td>';
                    }
                    echo '</tr>';
                }
            }
            if (count($users_available) > 0 && $usergroupdb_rw && $group->type == 'static' and $can_manage_usersgroups) {
                echo '<tr><form action="actions.php" method="post"><td>';
                echo '<input type="hidden" name="action" value="add" />';
                echo '<input type="hidden" name="name" value="User_UserGroup" />';
                echo '<input type="hidden" name="group" value="' . $id . '" />';
                echo '<select name="element">';
                foreach ($users_available as $user) {
                    echo '<option value="' . $user . '" >' . $user . '</option>';
                }
                echo '</select>';
                echo '</td><td><input type="submit" value="' . _('Add to this group') . '" /></td>';
                echo '</form></tr>';
            }
            echo '</table>';
            echo '</div>';
            echo '<br/>';
        }
    }
    // Publications part
    if (count($groups_apps_all) > 0) {
        echo '<div>';
        echo '<h2>' . _('List of publications for this group') . '</h1>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        if (count($groups_apps) > 0) {
            foreach ($groups_apps as $groups_app_id => $groups_app_name) {
                echo '<tr>';
                echo '<td><a href="appsgroup.php?action=manage&id=' . $groups_app_id . '">' . $groups_app_name . '</td>';
                if ($can_manage_publications) {
                    echo '<td>';
                    echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this publication?') . '\');">';
                    echo '<input type="hidden" name="action" value="del" />';
                    echo '<input type="hidden" name="name" value="Publication" />';
                    echo '<input type="hidden" name="group_u" value="' . $id . '" />';
                    echo '<input type="hidden" name="group_a" value="' . $groups_app_id . '" />';
                    echo '<input type="submit" value="' . _('Delete this publication') . '" />';
                    echo '</form>';
                    echo '</td>';
                }
                echo '</tr>';
            }
        }
        if (count($groups_apps_available) > 0 and $can_manage_publications) {
            echo '<tr><form action="actions.php" method="post"><td>';
            echo '<input type="hidden" name="action" value="add" />';
            echo '<input type="hidden" name="name" value="Publication" />';
            echo '<input type="hidden" name="group_u" value="' . $id . '" />';
            echo '<select name="group_a">';
            foreach ($groups_apps_available as $group_apps) {
                echo '<option value="' . $group_apps->id . '" >' . $group_apps->name . '</option>';
            }
            echo '</select>';
            echo '</td><td><input type="submit" value="' . _('Add this publication') . '" /></td>';
            echo '</form></tr>';
        }
        echo '</table>';
        echo '</div>';
    }
    // Scripts part
    if (count($groups_scripts_all) > 0) {
        echo '<div>';
        echo '<h2>' . _('List of scripts for this group') . '</h2>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        if (count($groups_scripts_all) > 0) {
            foreach ($groups_scripts_all as $script) {
                echo '<tr>';
                echo '<td><a href="script.php?action=manage&amp;id=' . $script["id"] . '">' . $script["name"] . '</a></td>';
                if ($can_manage_scripts) {
                    echo '<td><form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this user from this group?') . '\');">';
                    echo '<input type="hidden" name="name" value="Script_UserGroup" />';
                    echo '<input type="hidden" name="action" value="del" />';
                    echo '<input type="hidden" name="group" value="' . $id . '" />';
                    echo '<input type="hidden" name="element" value="' . $script["id"] . '" />';
                    echo '<input type="submit" value="' . _('Delete from this group') . '" />';
                    echo '</form></td>';
                }
                echo '</tr>';
            }
        }
        if (count($scripts_available) > 0 and $can_manage_scripts) {
            echo '<tr><form action="actions.php" method="post"><td>';
            echo '<input type="hidden" name="action" value="add" />';
            echo '<input type="hidden" name="name" value="Script_UserGroup" />';
            echo '<input type="hidden" name="group" value="' . $id . '" />';
            echo '<select name="element">';
            foreach ($scripts_available as $script) {
                echo '<option value="' . $script->id . '" >' . $script->name . '</option>';
            }
            echo '</select>';
            echo '</td><td><input type="submit" value="' . _('Add this script') . '" /></td>';
            echo '</form></tr>';
        }
        echo '</table>';
        echo '</div>';
    }
    // Servers publications part
    if (count($servers_groups_list) > 0) {
        echo '<div>';
        echo '<h2>' . _('List of published Server Groups for this group') . '</h1>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        if (count($servers_groups_published) > 0) {
            foreach ($servers_groups_published as $servers_group_id => $servers_group_name) {
                echo '<tr>';
                echo '<td><a href="serversgroup.php?action=manage&id=' . $servers_group_id . '">' . $servers_group_name . '</td>';
                if ($can_manage_publications) {
                    echo '<td>';
                    echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this publication?') . '\');">';
                    echo '<input type="hidden" name="action" value="del" />';
                    echo '<input type="hidden" name="name" value="UsersGroupServersGroup" />';
                    echo '<input type="hidden" name="users_group" value="' . $id . '" />';
                    echo '<input type="hidden" name="servers_group" value="' . $servers_group_id . '" />';
                    echo '<input type="submit" value="' . _('Delete this publication') . '" />';
                    echo '</form>';
                    echo '</td>';
                }
                echo '</tr>';
            }
        }
        if (count($servers_groups_list) > count($servers_groups_published) and $can_manage_publications) {
            echo '<tr><form action="actions.php" method="post"><td>';
            echo '<input type="hidden" name="action" value="add" />';
            echo '<input type="hidden" name="name" value="UsersGroupServersGroup" />';
            echo '<input type="hidden" name="users_group" value="' . $id . '" />';
            echo '<select name="servers_group">';
            foreach ($servers_groups_list as $servers_group) {
                if (array_key_exists($servers_group->id, $servers_groups_published)) {
                    continue;
                }
                echo '<option value="' . $servers_group->id . '" >' . $servers_group->name . '</option>';
            }
            echo '</select>';
            echo '</td><td><input type="submit" value="' . _('Add this publication') . '" /></td>';
            echo '</form></tr>';
        }
        echo '</table>';
        echo '</div>';
    }
    // Policy of this group
    echo '<div>';
    echo '<h2>' . _('Policy of this group') . '</h2>';
    echo '<table border="0" cellspacing="1" cellpadding="3">';
    foreach ($policy as $key => $value) {
        if ($value === false) {
            continue;
        }
        $extends_from_default = $default_policy[$key] === $value;
        $buffer = $extends_from_default === true ? ' (' . _('extend from default') . ')' : '';
        echo '<tr>';
        echo '<td>' . $key . ' ' . $buffer . '</td>';
        if ($can_manage_usersgroups && !$extends_from_default) {
            echo '<td>';
            echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this rule?') . '\');">';
            echo '<input type="hidden" name="name" value="UserGroup_PolicyRule" />';
            echo '<input type="hidden" name="action" value="del" />';
            echo '<input type="hidden" name="id" value="' . $group->id . '" />';
            echo '<input type="hidden" name="element" value="' . $key . '" />';
            echo '<input type="submit" value="' . _('Delete this rule') . '" />';
            echo '</form>';
            echo '</td>';
        }
        echo '</tr>';
    }
    if ($can_manage_usersgroups && count($policy_rules_disable) > 0 && array_search(false, $policy) !== false) {
        echo '<tr><form action="actions.php" method="post"><td>';
        echo '<input type="hidden" name="name" value="UserGroup_PolicyRule" />';
        echo '<input type="hidden" name="action" value="add" />';
        echo '<input type="hidden" name="id" value="' . $group->id . '" />';
        echo '<select name="element">';
        foreach ($policy as $key => $value) {
            if ($value === true) {
                continue;
            }
            echo '<option value="' . $key . '" >' . $key . '</option>';
        }
        echo '</select>';
        echo '</td><td><input type="submit" value="' . _('Add this rule') . '" /></td>';
        echo '</form></tr>';
    }
    echo '</table>';
    echo '</div>';
    echo '<br/>';
    if (is_module_enabled('SharedFolderDB')) {
        $all_sharedfolders = $_SESSION['service']->shared_folders_list();
        if (is_null($all_sharedfolders)) {
            $all_sharedfolders = array();
        }
        if (count($all_sharedfolders) > 0) {
            $available_sharedfolders = array();
            $used_sharedfolders = array();
            if ($group->hasAttribute('shared_folders')) {
                $data = $group->getAttribute('shared_folders');
                $mods_by_share = array();
                foreach ($data as $mode => $used_sharedfolders2) {
                    foreach ($used_sharedfolders2 as $share_id => $share_name) {
                        $used_sharedfolders[$share_id] = $share_name;
                        $mods_by_share[$share_id] = $mode;
                    }
                }
            }
            foreach ($all_sharedfolders as $sharedfolder) {
                if (array_key_exists($sharedfolder->id, $used_sharedfolders)) {
                    continue;
                }
                $available_sharedfolders[] = $sharedfolder;
            }
            echo '<br />';
            echo '<div>';
            echo '<h2>' . _('Shared Folders') . '</h1>';
            echo '<table border="0" cellspacing="1" cellpadding="3">';
            foreach ($used_sharedfolders as $sharedfolder_id => $sharedfolder_name) {
                echo '<tr>';
                echo '<td><a href="sharedfolders.php?action=manage&amp;id=' . $sharedfolder_id . '">' . $sharedfolder_name . '</a></td>';
                echo '<td>' . $mods_by_share[$sharedfolder_id] . '</td>';
                if ($can_manage_sharedfolders) {
                    echo '<td><form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this shared folder access?') . '\');">';
                    echo '<input type="hidden" name="name" value="SharedFolder_ACL" />';
                    echo '<input type="hidden" name="action" value="del" />';
                    echo '<input type="hidden" name="sharedfolder_id" value="' . $sharedfolder_id . '" />';
                    echo '<input type="hidden" name="usergroup_id" value="' . $group->id . '" />';
                    echo '<input type="submit" value="' . _('Delete access to this shared folder') . '" />';
                    echo '</form></td>';
                }
                echo '</tr>';
            }
            if (count($available_sharedfolders) > 0 && $can_manage_sharedfolders) {
                echo '<tr><form action="actions.php" method="post"><td>';
                echo '<input type="hidden" name="name" value="SharedFolder_ACL" />';
                echo '<input type="hidden" name="action" value="add" />';
                echo '<input type="hidden" name="usergroup_id" value="' . $group->id . '" />';
                echo '<select name="sharedfolder_id">';
                foreach ($available_sharedfolders as $sharedfolder) {
                    echo '<option value="' . $sharedfolder->id . '" >' . $sharedfolder->name . '</option>';
                }
                echo '</select>';
                echo '</td><td>';
                echo '<select name="mode">';
                echo '<option value="rw" >' . _('Read-write') . '</option>';
                echo '<option value="ro" >' . _('Read only') . '</option>';
                echo '</select>';
                echo '</td><td><input type="submit" value="' . _('Add access to this shared folder') . '" /></td>';
                echo '</form></tr>';
            }
            echo '</table>';
            echo '</div>';
        }
        echo '<br />';
    }
    echo '<div>';
    // Session Settings configuration
    echo '<h2>';
    echo _('Session Settings configuration');
    echo '</h2>';
    if ($prefs_of_a_group != array()) {
        foreach ($prefs_of_a_group as $container => $prefs_of_a_group_value) {
            echo '<fieldset class="prefssessionusergroup">';
            echo '<legend>' . $prefs->getPrettyName('general_' . $container) . '</legend>';
            echo '<form action="actions.php" method="post">';
            $key_name = 'general';
            echo '<input type="hidden" name="container" value="' . $container . '" />';
            // from admin/functions.inc.php
            $color = 0;
            if (count($prefs_of_a_group_value) != 0) {
                echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="3" style="margin-bottom: 10px;">';
                // TODO
                echo '<tr  class="title">';
                echo '<th>' . _('Name') . '</th>';
                echo '<th>' . _('Default value') . '</th>';
                echo '<th>' . _('Value') . '</th>';
                echo '<th>' . _('Action') . '</th>';
                echo '<tr>';
                foreach ($prefs_of_a_group_value as $element_key => $config_element) {
                    echo '<tr class="content' . ($color % 2 + 1) . '">';
                    echo '<td style="width: 250px;">';
                    echo '<span onmouseover="showInfoBulle(\'' . str_replace("'", "&rsquo;", $config_element->description_detailed) . '\'); return false;" onmouseout="hideInfoBulle(); return false;">' . $config_element->label . '</span>';
                    echo '<td>';
                    $default_element = $session_prefs[$container][$config_element->id];
                    $default_element->setFormSeparator('NaN');
                    // it must be different of ___
                    $default_element->setPath(array('key_name' => $key_name, 'container' => $container, 'element_id' => $config_element->id));
                    echo $default_element->toHTML(true);
                    echo '</td>';
                    echo '</td>';
                    echo '<td style="padding: 3px;">';
                    print_element($key_name, $container, $element_key, $config_element);
                    echo '</td>';
                    echo '<td>';
                    echo '<input type="button" value="' . _('Remove this overridden setting') . '" onclick="usergroup_settings_remove(\'' . $group->id . '\',\'' . $container . '\',\'' . $config_element->id . '\'); return false;"/>';
                    echo '</td>';
                    echo '</tr>';
                    $color++;
                }
                // end from
                echo '<tr class="content' . ($color % 2 + 1) . '">';
                echo '<td colspan="3"></td>';
                echo '<td>';
                echo '<input type="hidden" name="name" value="UserGroup_settings" />';
                echo '<input type="hidden" name="container" value="' . $container . '" />';
                echo '<input type="hidden" name="unique_id" value="' . $group->id . '" />';
                echo '<input type="hidden" name="action" value="modify" />';
                echo '<input type="submit" value="' . _('Save settings') . '" />';
                echo '</td>';
                echo '</tr>';
                echo '</table>';
                echo '</form>';
            }
            if ($unuse_settings[$container] != array()) {
                echo '<form action="actions.php" method="post">';
                echo '<input type="hidden" name="name" value="UserGroup_settings" />';
                echo '<input type="hidden" name="container" value="' . $container . '" />';
                echo '<input type="hidden" name="unique_id" value="' . $group->id . '" />';
                echo '<input type="hidden" name="action" value="add" />';
                echo '<select name="element_id">';
                foreach ($unuse_settings[$container] as $setting_name => $setting_content) {
                    echo '<option value="' . $setting_name . '" >' . $setting_content->label . '</option>';
                }
                echo '</select>';
                echo ' ';
                echo '<input type="submit" value="' . _('Add this setting') . '" />';
                echo '</form>';
            }
            echo '</fieldset>';
        }
    }
    echo '</div>';
    // Session Settings configuration
    echo "\n\n\n";
    echo '</div>';
    page_footer();
    die;
}
示例#20
0
function query_url_post($url_, $string_ = NULL, $log_returned_data_ = true)
{
    Logger::debug('main', "query_url_post({$url_}, {$string_}, {$log_returned_data_})");
    $hr = new HttpRequest($url_, 'POST', array('postFields' => $string_));
    $data = $hr->send();
    if ($data === false) {
        Logger::error('main', "query_url_post({$url_}) error code: " . $hr->getResponseErrno() . " text: '" . $hr->getResponseError() . "'");
    } else {
        if (str_startswith($hr->getResponseContentType(), 'text/') && $log_returned_data_ === true) {
            Logger::debug('main', "query_url_post({$url_}) returntext: '{$data}'");
        }
    }
    return $data;
}
示例#21
0
 function show_html($summary, $annotations)
 {
     global $CFG, $USER;
     // Get the course.  This can't be passed as a GET parameter because this URL could be via the
     // Atom feed, and the Atom feed is generated exclusively by annotation code which doesn't know
     // that much about Moodle.  So the handler has to query it based on a discussion ID or the like.
     $this->course = null;
     $this->courseid = $summary->handler->courseid;
     if (null != $this->courseid) {
         if (!($this->course = get_record("course", "id", $this->courseid))) {
             error("Course ID is incorrect");
         }
         // Ok, now this is probably very wrong.  If the user looks for annotations within a course,
         // it requires a login.  Without the course (i.e. in a more general search), it doesn't!
         // I would eleminate this, but I don't really know how Moodle security works. #geof#
         if ($this->course->category) {
             require_login($this->course->id);
         }
     }
     // Keep for debugging:
     // echo "<h2>Query</h2><pre>".$query->sql( 'a.id' )."</pre>";
     // Show header
     $swwwroot = htmlspecialchars($CFG->wwwroot);
     $this->show_header();
     $keywords = isloggedin() ? annotation_keywords_db::list_keywords($USER->id) : array();
     $keywordhash = array();
     for ($i = 0; $i < count($keywords); ++$i) {
         $keyword = $keywords[$i];
         $keywordhash[$keyword->name] = true;
     }
     // print search header
     //  * my annotations
     //  * shared annotations
     //  * instructor annotations
     //  * annotations of my work
     $username = $summary->user ? $summary->user->username : '';
     $ofusername = $summary->ofuser ? $summary->ofuser->username : '';
     echo "<form id='annotation-search' method='get' action='summary.php'>\n";
     echo "<fieldset>\n";
     echo "<label for='search-of'>" . get_string('prompt_find', ANNOTATION_STRINGS) . "</label>\n";
     echo "<input type='hidden' name='search-of' id='search-of' value='" . s($ofusername) . "'/>\n";
     echo "<input type='hidden' name='u' id='u' value='" . s($username) . "'/>\n";
     echo "<input type='text' id='search-text' name='q' value='" . s($summary->text) . "'/>\n";
     echo "<input type='submit' value='" . get_string('go') . "'/>\n";
     echo "<input type='hidden' name='url' value='" . s($summary->url) . "'/>\n";
     helpbutton('annotation_summary', get_string('summary_help', ANNOTATION_STRINGS), 'block_marginalia');
     echo "</fieldset>\n";
     echo "</form>";
     // If this page is an error, explain what it's about
     if ('range-mismatch' == $this->errorpage) {
         echo '<p class="error"><em class="range-error">!</em>' . get_string('summary_range_error', ANNOTATION_STRINGS) . "</p>\n";
     }
     echo '<p id="query">' . get_string('prompt_search_desc', ANNOTATION_STRINGS) . ' ' . $summary->desc_with_links(null) . ":</p>\n";
     $cursection = null;
     $cursectiontype = null;
     $curuser = null;
     $cururl = null;
     // make sure some records came back
     if (null != $annotations) {
         // Convert $annotations to an indexable array (why isn't it?  for efficiency with large data sets?)
         $annotationa = array();
         foreach ($annotations as $annotation) {
             $annotationa[] = $annotation;
         }
         $ncols = 6;
         echo '<table cellspacing="0" class="annotations">' . "\n";
         for ($annotationi = 0; $annotationi < count($annotationa); ++$annotationi) {
             $annotation = $annotationa[$annotationi];
             // Display a heading for each new section URL
             if ($annotation->section_type != $cursectiontype || $annotation->section_url != $cursection) {
                 if ($cursection != null) {
                     echo "</tbody>\n";
                 }
                 echo "<thead><tr><th colspan='{$ncols}'>";
                 $a->section_type = htmlspecialchars($annotation->section_type);
                 echo '<h3>' . s($annotation->section_type) . '</h3>: ' . "<a href='" . s($annotation->section_url) . "' title='" . get_string('prompt_section', ANNOTATION_STRINGS, $a) . "'>" . s($annotation->section_name) . "</a>";
                 if ($annotation->section_url != $summary->url) {
                     $tsummary = $summary->for_url($annotation->section_url);
                     $turl = $tsummary->summary_url();
                     echo "<a class='zoom' title='" . get_string('zoom_url_hover', ANNOTATION_STRINGS, $annotation) . "' href='" . s($turl) . "'>" . AN_FILTERICON_HTML . "</a>\n";
                 }
                 echo '</th></tr></thead>' . "\n";
                 if (AN_SUMMARYHEADINGSTOP) {
                     $this->show_column_headings('top');
                 }
                 echo '<tbody>' . "\n";
                 $cursection = $annotation->section_url;
                 $cursectiontype = $annotation->section_type;
                 $curuser = $annotation->userid;
                 $cururl = null;
             }
             // For each new url, display the title and author
             if ($annotation->url != $cururl) {
                 //|| $annotation->userid != $curUser ) {
                 $cururl = $annotation->url;
                 $curuser = $annotation->userid;
                 echo "<tr class='fragment first'>";
                 // Figure out how many rows this source will span
                 $nrows = 1;
                 for ($j = $annotationi + 1; $j < count($annotationa); ++$j) {
                     if ($annotationa[$j]->url != $cururl) {
                         break;
                     }
                     $nrows += 1;
                 }
                 // Only prefix the URL with the site root if it doesn't already have a scheme
                 // Only check for http and https schemes to prevent obscure attacks
                 $url = $annotation->url;
                 if (!(str_startswith($url, 'http://') || str_startswith($url, 'https://'))) {
                     $url = $CFG->wwwroot . $annotation->url;
                 }
                 echo "<th rowspan='{$nrows}'>";
                 $url = MarginaliaHelper::isUrlSafe($url) ? $url : '';
                 $a->row_type = $annotation->row_type;
                 $a->author = $annotation->quote_author_fullname;
                 echo "<a class='url' href='" . s($url) . "' title='" . get_string('prompt_row', ANNOTATION_STRINGS, $a) . "'>";
                 echo s($annotation->quote_title) . '</a>';
                 echo "<br/>by <span class='quote-author'>" . s($annotation->quote_author_fullname) . "</span>\n";
                 // Link to filter only annotations by this user
                 if (!$summary->ofuser || $annotation->quote_author_username != $summary->ofuser->username) {
                     $tuser = get_record('user', 'username', $annotation->quote_author_username);
                     if ($tuser) {
                         $tsummary = $summary->for_ofuser($tuser);
                         $turl = $tsummary->summary_url();
                         $a->fullname = $annotation->quote_author_fullname;
                         echo "<a class='zoom' title='" . get_string('zoom_author_hover', ANNOTATION_STRINGS, $a) . "' href='" . s($turl) . "'>" . AN_FILTERICON_HTML . "</a>\n";
                     }
                 }
                 echo "</th>\n";
             } else {
                 echo "<tr>";
             }
             // Show the quoted text
             echo "<td class='quote'>";
             p($annotation->quote);
             echo "</td>\n";
             // Show the note
             echo "<td class='note'>";
             if (!$annotation->note) {
                 echo '&#160;';
             } else {
                 p($annotation->note);
             }
             if (!$summary->exactmatch && array_key_exists($annotation->note, $keywordhash)) {
                 $tsummary = $summary->for_text($annotation->note, true);
                 echo "<a class='zoom' title='" . get_string('zoom_match_hover', ANNOTATION_STRINGS) . "' href='" . s($tsummary->summary_url()) . "'>" . AN_FILTERICON_HTML . "</a>\n";
             }
             echo "</td>\n";
             // Show edit controls or the user who created the annotation
             echo "<td class='user" . (isloggedin() && $annotation->userid == $USER->id ? ' isloginuser' : '') . "'>\n";
             // Smartquote button
             if (AN_USESMARTQUOTE) {
                 // $SMARTQUOTE_SYMBOL = AN_SMARTQUOTEICON_PHP; //'&#9850;';
                 $sqid = s('sq' . $annotation->id);
                 $sqtitle = get_string('smartquote_annotation', ANNOTATION_STRINGS);
                 echo "<button class='smartquote' id='{$sqid}' title='{$sqtitle}'>" . AN_SMARTQUOTEICON_HTML . "</button>\n";
             }
             // Controls for current user
             if (isloggedin() && $annotation->userid == $USER->id) {
                 $AN_SUN_SYMBOL = '&#9675;';
                 $AN_MOON_SYMBOL = '&#9670;';
                 $access_str = AN_ACCESS_PUBLIC & $annotation->access_perms ? 'public' : 'private';
                 echo "<button class='share-button access-{$access_str}' onclick='window.annotationSummary.shareAnnotationPublicPrivate(this,{$annotation->id});'>" . ($annotation->access_perms & AN_ACCESS_PUBLIC ? $AN_SUN_SYMBOL : $AN_MOON_SYMBOL) . "</button>";
                 echo "<button class='delete-button' onclick='window.annotationSummary.deleteAnnotation({$annotation->id});'>x</button>\n";
             }
             // User name (or "me" for current user)
             $displayusername = s($annotation->username);
             $hiddenusername = '';
             $class = 'user-name';
             if (isloggedin() && $annotation->userid == $USER->id) {
                 $hiddenusername = "******";
                 $displayusername = get_string('me', ANNOTATION_STRINGS);
                 $class = '';
             }
             $url = $CFG->wwwroot . $annotation->url;
             if (MarginaliaHelper::isUrlSafe($url)) {
                 echo "<a class='{$class}' onclick='setAnnotationUser(\"" . s($annotation->userid) . "\")' href='" . s($url) . "'>" . "{$displayusername}</a>\n";
             } else {
                 echo "<span class='{$class}'>{$displayUserName}</span>\n";
             }
             echo $hiddenusername;
             // Link to filter only annotations by this user
             if (!$summary->user || $annotation->userid != $summary->user->username) {
                 $tuser = get_record('user', 'username', $annotation->username);
                 if ($tuser) {
                     $tsummary = $summary->for_user($tuser);
                     $turl = $tsummary->summary_url();
                     $a->fullname = $annotation->fullname;
                     echo "<a class='zoom' title='" . get_string('zoom_user_hover', ANNOTATION_STRINGS, $a) . "' href='" . s($turl) . "'>" . AN_FILTERICON_HTML . "</a>\n";
                 }
             }
             echo "</td>\n";
             echo "</tr>\n";
         }
         // Build scripts for individual buttons
         echo "<script type='text/javascript'>\n";
         for ($annotationi = 0; $annotationi < count($annotationa); ++$annotationi) {
             $annotation = $annotationa[$annotationi];
             $sqid = s('sq' . $annotation->id);
             $tuserid = s($annotation->userid);
             echo "  addEvent(document.getElementById('{$sqid}'),'click',function() {" . "    window.annotationSummary.quote('{$sqid}','{$tuserid}'); } );";
         }
         echo "</script>\n";
         if ($cururl != null) {
             echo "</tbody>\n";
         }
         if (!AN_SUMMARYHEADINGSTOP) {
             $this->show_column_headings('');
         }
         echo "</table>\n";
     }
     //$moodlePath = getMoodlePath( );
     // Provide a feed URL.  I don't know how to do authentication for the feed, so for now
     // if a login is required I won't include the feature.
     if (!ANNOTATION_REQUIRE_USER) {
         $turl = $summary->get_feed_url('atom');
         echo "<p class='feed' title='" . get_string('atom_feed', ANNOTATION_STRINGS) . "'><a href='" . s($turl) . "'><img border='0' alt='" . get_string('atom_feed', ANNOTATION_STRINGS) . "' src='" . s($CFG->wwwroot) . "/pix/i/rss.gif'/>" . '</a> ' . get_string('atom_feed_desc', ANNOTATION_STRINGS) . "</p>\n";
     }
     print_footer($this->course);
     $logurl = $_SERVER['REQUEST_URI'];
     $urlparts = parse_url($logurl);
     $logurl = array_key_exists('query', $urlparts) ? $urlparts['query'] : null;
     add_to_log(null, 'annotation', 'summary', 'summary.php' . ($logurl ? '?' . $logurl : ''), $summary->desc(null));
 }
示例#22
0
 public static function join_filters($filters, $rule)
 {
     // rule can be & or |
     $res = array();
     foreach ($filters as $filter) {
         if (is_null($filter)) {
             continue;
         }
         $filter = trim($filter);
         if (strlen($filter) == 0) {
             continue;
         }
         if (!(str_startswith($filter, '(') and str_endswith($filter, ')'))) {
             $filter = '(' . $filter . ')';
         }
         array_push($res, $filter);
     }
     switch (count($res)) {
         case 0:
             return null;
         case 1:
             return $res[0];
         default:
             return '(' . $rule . implode('', $res) . ')';
     }
 }
示例#23
0
 function show_html($annotations, $annotation_count)
 {
     global $CFG, $USER, $PAGE, $OUTPUT, $DB;
     $PAGE->set_url($this->summary->summary_url());
     $blockpath = '/blocks/marginalia';
     // was ANNOTATION_PATH
     $PAGE->requires->css($blockpath . '/summary-styles.php');
     // This loads way more than is needed here, but reduces code paths
     // and hence bugs.
     $moodlemia = moodle_marginalia::get_instance();
     $profile = $moodlemia->get_profile($this->summary->summary_url());
     $profile->emit_requires();
     $PAGE->requires->js($blockpath . '/summary.js', true);
     // Get the course.  This can't be passed as a GET parameter because this URL could be via the
     // Atom feed, and the Atom feed is generated exclusively by annotation code which doesn't know
     // that much about Moodle.  So the handler has to query it based on a discussion ID or the like.
     $this->course = null;
     $this->courseid = $this->summary->handler->courseid;
     if (null != $this->courseid) {
         if (!($this->course = $DB->get_record("course", array('id' => $this->courseid)))) {
             error("Course ID is incorrect");
         }
         // Ok, now this is probably very wrong.  If the user looks for annotations within a course,
         // it requires a login.  Without the course (i.e. in a more general search), it doesn't!
         // I would eleminate this, but I don't really know how Moodle security works. #geof#
         if ($this->course->category) {
             require_login($this->course->id);
         }
     }
     // #geof#: not quite correct - should fetch the URL from the summary object
     $PAGE->set_url('/mod/forum/summary.php');
     if (null != $this->course) {
         $PAGE->set_title($this->course->shortname . ": " . get_string('summary_title', ANNOTATION_STRINGS));
         $PAGE->set_heading($this->course->fullname);
     } else {
         $PAGE->set_title(get_string('summary_title', ANNOTATION_STRINGS));
         $PAGE->set_heading(get_string('summary_title', ANNOTATION_STRINGS));
     }
     // #geof# Must change to split requires from inline JS:
     if ($this->logger && $this->logger->is_active()) {
         $this->logger->header_html();
     }
     if (null != $this->course && $this->course->category) {
         $PAGE->navbar->add($this->course->shortname, $CFG->wwwroot . '/course/view.php?id=' . $this->course->id);
     }
     $PAGE->navbar->add(get_string('summary_title', ANNOTATION_STRINGS));
     echo $OUTPUT->header();
     $swwwroot = htmlspecialchars($CFG->wwwroot);
     if (isloggedin()) {
         $profile->emit_body();
         $sannotationpath = s(ANNOTATION_PATH);
         echo "<script language='JavaScript' type='text/javascript'>\n" . "var annotationService = new RestAnnotationService('{$sannotationpath}/annotate.php', " . "{ csrfCookie: 'MoodleSession" . $CFG->sessioncookie . "', noPutDelete: true } );\n" . "window.annotationSummary = new AnnotationSummary('{$swwwroot}', {" . " \n annotationService: annotationService" . ",\n userid: " . (int) $USER->id . ",\n useLog: " . ($this->logger && $this->logger->is_active() ? 'true' : 'false') . ",\n csrfCookie: 'MoodleSession" . $CFG->sessioncookie . "'" . "} );\n" . "window.preferences = new Preferences( new RestPreferenceService('{$sannotationpath}/user-preference.php' ) );\n" . "</script>\n";
     }
     // Needed later to determine whether a given annotation is a keyword
     $keywords = isloggedin() ? annotation_keywords_db::list_keywords($USER->id) : array();
     $keywordhash = array();
     for ($i = 0; $i < count($keywords); ++$i) {
         $keyword = $keywords[$i];
         $keywordhash[$keyword->name] = true;
     }
     // print search header
     //  * my annotations
     //  * shared annotations
     //  * instructor annotations
     //  * annotations of my work
     echo "<form id='annotation-search' method='get' action='summary.php'>\n";
     echo "<fieldset>\n";
     echo "<label for=''>" . get_string('prompt_find', ANNOTATION_STRINGS) . "</label>\n";
     if ($this->summary->ofuser) {
         echo "<input type='hidden' name='search-of' id='search-of' value='" . s($this->moodlemia->fullname($this->summary->ofuser)) . "'/>\n";
     }
     if ($this->summary->user) {
         echo "<input type='hidden' name='u' id='u' value='" . s($this->moodlemia->fullname($this->summary->user)) . "'/>\n";
     }
     echo "<input type='text' id='search-text' name='q' value='" . s($this->summary->text) . "'/>\n";
     echo "<input type='submit' value='" . get_string('go') . "'/>\n";
     echo "<input type='hidden' name='url' value='" . s($this->summary->url) . "'/>\n";
     //		echo $OUTPUT->help_icon( 'annotation_summary', ANNOTATION_STRINGS ); //'block_marginalia', get_string( 'summary_help', ANNOTATION_STRINGS ) );
     echo "</fieldset>\n";
     echo "</form>";
     // If this page is an error, explain what it's about
     if ('range-mismatch' == $this->errorpage) {
         echo '<p class="error"><em class="range-error">!</em>' . get_string('summary_range_error', ANNOTATION_STRINGS) . "</p>\n";
     }
     $a = new object();
     $a->n = $annotations ? count($annotations) : 0;
     $a->m = $annotation_count;
     echo '<p id="query">' . get_string('prompt_search_desc', ANNOTATION_STRINGS, $a) . ' ' . $this->summary->desc_with_links(null) . ":</p>\n";
     $cursection = null;
     $cursectiontype = null;
     $curuser = null;
     $cururl = null;
     // make sure some records came back
     if (null != $annotations) {
         // Convert $annotations to an indexable array (why isn't it?  for efficiency with large data sets?)
         $annotationa = array();
         foreach ($annotations as $annotation) {
             $annotationa[] = $annotation;
         }
         $ncols = 6;
         if (AN_SUMMARY_ORDER_TIME == $this->summary->orderby) {
             $ncols += 1;
         }
         echo '<table cellspacing="0" class="annotations">' . "\n";
         for ($annotationi = 0; $annotationi < count($annotationa); ++$annotationi) {
             $annotation = $annotationa[$annotationi];
             // Display a heading for each new section URL
             if ($annotation->section_type != $cursectiontype || $annotation->section_url != $cursection) {
                 if ($cursection != null) {
                     echo "</tbody>\n";
                 }
                 echo "<thead><tr><th colspan='{$ncols}'>";
                 $a->section_type = htmlspecialchars($annotation->section_type);
                 echo '<h3>' . s($annotation->section_type) . '</h3>: ' . "<a href='" . s($annotation->section_url) . "' title='" . get_string('prompt_section', ANNOTATION_STRINGS, $a) . "'>" . s($annotation->section_name) . "</a>";
                 if ($annotation->section_url != $this->summary->url) {
                     $tsummary = $this->summary->derive(array('url' => $annotation->section_url));
                     $turl = $tsummary->summary_url();
                     echo "<a class='zoom' title='" . get_string('zoom_url_hover', ANNOTATION_STRINGS, $annotation) . "' href='" . s($turl) . "'>" . AN_FILTERICON_HTML . "</a>\n";
                 }
                 echo '</th></tr></thead>' . "\n";
                 if (AN_SUMMARYHEADINGSTOP) {
                     $this->show_column_headings($this->summary, 'top');
                 }
                 echo '<tbody>' . "\n";
                 $cursection = $annotation->section_url;
                 $cursectiontype = $annotation->section_type;
                 $curuser = $annotation->userid;
                 $cururl = null;
             }
             // For each new url, display the title and author
             if ($annotation->url != $cururl) {
                 //|| $annotation->userid != $curUser ) {
                 $cururl = $annotation->url;
                 $curuser = $annotation->userid;
                 echo "<tr class='fragment first'>";
                 // Figure out how many rows this source will span
                 $nrows = 1;
                 for ($j = $annotationi + 1; $j < count($annotationa); ++$j) {
                     if ($annotationa[$j]->url != $cururl) {
                         break;
                     }
                     $nrows += 1;
                 }
                 // Only prefix the URL with the site root if it doesn't already have a scheme
                 // Only check for http and https schemes to prevent obscure attacks
                 $url = $annotation->url;
                 if (!(str_startswith($url, 'http://') || str_startswith($url, 'https://'))) {
                     $url = $CFG->wwwroot . $annotation->url;
                 }
                 echo "<th rowspan='{$nrows}'>";
                 $url = MarginaliaHelper::isUrlSafe($url) ? $url : '';
                 $a->row_type = $annotation->row_type;
                 $a->author = $this->moodlemia->fullname2($annotation->quote_author_firstname, $annotation->quote_author_lastname);
                 echo "<a class='url' href='" . s($url) . "' title='" . get_string('prompt_row', ANNOTATION_STRINGS, $a) . "'>";
                 echo s($annotation->quote_title) . '</a>';
                 echo "<br/>by <span class='quote-author'>" . s($a->author) . "</span>\n";
                 // Link to filter only annotations by this user
                 if (!$this->summary->ofuser || $annotation->quote_author_username != $this->summary->ofuser->username) {
                     $tsummary = $this->summary->derive(array('ofuserid' => $annotation->quote_author_id));
                     $turl = $tsummary->summary_url();
                     $a->fullname = $this->moodlemia->fullname2($annotation->quote_author_firstname, $annotation->quote_author_lastname);
                     echo $this->zoom_link($tsummary->summary_url(), get_string('zoom_author_hover', ANNOTATION_STRINGS, $a));
                 }
                 echo "</th>\n";
             } else {
                 echo "<tr>";
             }
             // Show the quoted text
             echo "<td class='quote'>";
             p($annotation->quote);
             echo "</td>\n";
             // Show the note
             echo "<td class='note'>";
             if (!$annotation->note) {
                 echo '&#160;';
             } else {
                 echo s($annotation->note);
             }
             if (!$this->summary->exactmatch && array_key_exists($annotation->note, $keywordhash)) {
                 $tsummary = $this->summary->derive(array('text' => $annotation->note, 'exactmatch' => true));
                 echo ' ' . $this->zoom_link($tsummary->summary_url(), get_string('zoom_match_hover', ANNOTATION_STRINGS));
             }
             echo "</td>\n";
             // Show annotation time (if requested)
             if (AN_SUMMARY_ORDER_TIME == $this->summary->orderby) {
                 echo "<td class='modified'>" . s(date('Y-m-d G:i', $annotation->modified)) . "</td>\n";
             }
             // Show edit controls or the user who created the annotation
             echo "<td class='user" . (isloggedin() && $annotation->userid == $USER->id ? ' isloginuser' : '') . "'>\n";
             // Smartquote button
             if (AN_USESMARTQUOTE) {
                 // $SMARTQUOTE_SYMBOL = AN_SMARTQUOTEICON_PHP; //'&#9850;';
                 $sqid = s('sq' . $annotation->id);
                 $sqtitle = get_string('smartquote_annotation', ANNOTATION_STRINGS);
                 echo "<button class='smartquote' id='{$sqid}' title='{$sqtitle}'>" . AN_SMARTQUOTEICON_HTML . "</button>\n";
             }
             // Controls for current user
             if (isloggedin() && $annotation->userid == $USER->id) {
                 $delid = s('del' . $annotation->id);
                 $deltitle = get_string('js_delete_annotation_button', ANNOTATION_STRINGS);
                 echo "<button class='delete-button' id='{$delid}' title='{$deltitle}'>x</button>\n";
             }
             // User name (or "me" for current user)
             $displayusername = s($this->moodlemia->fullname2($annotation->firstname, $annotation->lastname));
             $hiddenusername = '';
             $class = 'user-name';
             if (isloggedin() && $annotation->userid == $USER->id) {
                 $hiddenusername = "******";
                 $displayusername = get_string('me', ANNOTATION_STRINGS);
                 $class = '';
             }
             $url = $CFG->wwwroot . $annotation->url;
             if (MarginaliaHelper::isUrlSafe($url)) {
                 echo "<a class='{$class}' onclick='setAnnotationUser(\"" . s($annotation->userid) . "\")' href='" . s($url) . "'>" . "{$displayusername}</a>\n";
             } else {
                 echo "<span class='{$class}'>{$displayusername}</span>\n";
             }
             echo $hiddenusername;
             // Link to filter only annotations by this user
             if (!$this->summary->user || $annotation->userid != $this->summary->user->username) {
                 $tsummary = $this->summary->derive(array('userid' => $annotation->userid));
                 $turl = $tsummary->summary_url();
                 $a->fullname = $this->moodlemia->fullname2($annotation->firstname, $annotation->lastname);
                 echo $this->zoom_link($tsummary->summary_url(), get_string('zoom_user_hover', ANNOTATION_STRINGS, $a));
             }
             echo "</td>\n";
             echo "</tr>\n";
         }
         // Build scripts for individual buttons
         echo "<script type='text/javascript'>\n";
         for ($annotationi = 0; $annotationi < count($annotationa); ++$annotationi) {
             $annotation = $annotationa[$annotationi];
             if (AN_USESMARTQUOTE) {
                 // HTML ID of smartquote button
                 $sqid = s('sq' . $annotation->id);
                 $tuserid = s($annotation->userid);
                 echo "  addEvent(document.getElementById('{$sqid}'),'click',function() {" . "    window.annotationSummary.quote('{$sqid}','{$tuserid}'); } );";
             }
             if (isloggedin() && $annotation->userid == $USER->id) {
                 // HTML ID of delete button
                 $delid = s('del' . $annotation->id);
                 echo "  addEvent(document.getElementById('{$delid}'),'click',function() {" . "    window.annotationSummary.deleteAnnotation('{$delid}'," . (int) $annotation->id . "); } );\n";
             }
         }
         echo "</script>\n";
         if ($cururl != null) {
             echo "</tbody>\n";
         }
         if (!AN_SUMMARYHEADINGSTOP) {
             $this->show_column_headings('');
         }
         echo "</table>\n";
     }
     marginalia_summary_lib::show_result_pages($this->first, $annotation_count, $this->maxrecords, $this->summary->summary_url('{first}'));
     /*
     		// Show the list of result pages
     		$npages = ceil( $annotation_count / $this->maxrecords );
     		if ( $npages > 1 )
     		{
     			$this_page = 1 + floor( ( $this->first - 1 ) / $this->maxrecords );
     			echo "<ol class='result-pages'>\n";
     			for ( $i = 1; $i <= $npages;  ++$i )
     			{
     				if ( $i == $this_page )
     					echo "  <li>".$i."</li>\n";
     				else
     					echo "  <li><a href='".s($this->summary->summary_url('{first}')."'>".$i."</a></li>\n";
     			}
     			echo "</ol>\n";
     		}
     */
     //$moodlePath = getMoodlePath( );
     // Link for sorting by date or document order
     if ($this->summary->orderby == AN_SUMMARY_ORDER_DOCUMENT) {
         $tsummary = $this->summary->derive(array('orderby' => AN_SUMMARY_ORDER_TIME));
         echo "<p><a href='" . s($tsummary->summary_url()) . "'>" . get_string('summary_sort_time', ANNOTATION_STRINGS) . "</a></p>\n";
     } else {
         $tsummary = $this->summary->derive(array('orderby' => AN_SUMMARY_ORDER_DOCUMENT));
         echo "<p><a href='" . s($tsummary->summary_url()) . "'>" . get_string('summary_sort_document', ANNOTATION_STRINGS) . "</a></p>\n";
     }
     /*		Feed removed because Moodle should require a login for it to be of much
     		use, and the feed reader would then need to authenticate.  So it's likely
     		to be more frustrating than useful.
     		
     		// Provide a feed URL.  I don't know how to do authentication for the feed, so for now
     		// if a login is required I won't include the feature.
     		if ( ! ANNOTATION_REQUIRE_USER )  {
     			$tsummary = $this->summary->derive( array( 'orderby' => AN_SUMMARY_ORDER_TIME ) );
     			$turl = $tsummary->get_feed_url( 'atom' );
     			echo "<p class='feed' title='".get_string( 'atom_feed', ANNOTATION_STRINGS )
     				."'><a href='".s($turl)."'><img border='0' alt='"
     				.get_string( 'atom_feed', ANNOTATION_STRINGS )."' src='".s( $CFG->wwwroot )."/pix/i/rss.gif'/>"
     				. '</a> '.get_string( 'atom_feed_desc', ANNOTATION_STRINGS )."</p>\n";
     		}
     */
     echo "<p><a href='help.php?component=block_marginalia&topic=annotation_summary'>" . get_string('annotation_summary_help_link', ANNOTATION_STRINGS) . '</a></p>';
     $OUTPUT->footer($this->course);
     $logurl = $_SERVER['REQUEST_URI'];
     $urlparts = parse_url($logurl);
     $logurl = array_key_exists('query', $urlparts) ? $urlparts['query'] : null;
     $this->moodlemia->moodle_log('summary', 'summary.php' . ($logurl ? '?' . $logurl : ''), $this->summary->desc(null));
     // Marginalia logging
     if ($this->logger && $this->logger->is_active()) {
         $this->logger->summarizeAnnotations($this->summary->summary_url(), $this->summary->desc());
     }
 }
示例#24
0
                 if (!$userGroupDB->isWriteable()) {
                     die_error(_('User Group Database not writeable'), __FILE__, __LINE__);
                 }
             }
             if (!$userGroupDB->remove($group)) {
                 popup_error(sprintf(_("Unable to remove usergroup '%s'"), $id));
             }
             popup_info(sprintf(_("UserGroup '%s' successfully deleted"), $group->name));
         }
         redirect('usersgroup.php');
     }
 }
 if ($_REQUEST['action'] == 'modify') {
     if (isset($_REQUEST['id'])) {
         $id = $_REQUEST['id'];
         if (str_startswith($id, 'static_') && !$userGroupDB->isWriteable()) {
             die_error(_('User Group Database not writeable'), __FILE__, __LINE__);
         }
         $group = $userGroupDB->import($id);
         if (!is_object($group)) {
             popup_error(sprintf(_("Failed to import Usergroup '%s'"), $id));
             redirect();
         }
         $has_change = false;
         if (isset($_REQUEST['name_group'])) {
             $group->name = $_REQUEST['name_group'];
             $has_change = true;
         }
         if (isset($_REQUEST['description'])) {
             $group->description = $_REQUEST['description'];
             $has_change = true;
示例#25
0
文件: VCFDrugs.php 项目: bciv/COMS
function GetNDFLldf()
{
    //Set Variables
    //$host = '54.83.44.110';
    $host = $_SESSION['vista'];
    //$username = '******';
    $username = $_SESSION['sshusr'];
    $password = '';
    $login = '******';
    //$loginpass = '******';
    $loginpass = $_SESSION['sshpwd'];
    $csession = 'csession cache355';
    $ssh = new Net_SSH2($host);
    if (!$ssh->login($username, $password)) {
        exit('Login Failed');
    }
    $ssh->write("{$login}\r");
    $ssh->write("{$loginpass}\r");
    sleep(3);
    $ssh->write("CPRS1234\r");
    $ssh->write("CPRS4321\$\r");
    sleep(3);
    $ssh->write("\r");
    $ssh->write("FM\r");
    $ssh->write("Other\r");
    $ssh->write("RX\r");
    $ssh->write("PSN\r");
    $ssh->write("RPRT\r");
    $ssh->write("LDF\r");
    $countr = 0;
    while ($countr <= 1000) {
        $ssh->write("\r");
        $countr++;
    }
    sleep(1);
    //Set SSH Timeout
    $ssh->setTimeout(1);
    //Read Results
    $SSHresults = $ssh->read();
    $txtremove = array("                                                      LOCAL DRUG LIST (ALPHABETI\nC)#   Not on National Formulary\n  R   National Formulary Restriction\n   \nLOCAL DRUG NAME                                   INACTIVE               DEA\n                                                                                \n    NDC                                             DATE");
    $SSHresultsNew = str_replace($txtremove, "", $SSHresults);
    $myFile = writeDrugFile($SSHresultsNew);
    $lineNum = 1;
    $count = 1;
    while ($count <= 194) {
        delLineFromFile($myFile, $lineNum);
        $count++;
    }
    $lineNum2 = 12741;
    $count2 = 1;
    while ($count2 <= 151) {
        delLineFromFile($myFile, $lineNum2);
        $count2++;
    }
    //Delete SQL
    $Dquery = "DELETE FROM LookUp WHERE Lookup_Type = 2";
    $DelDrugs = sqlsrv_query($conn, $Dquery);
    $str = file_get_contents($myFile);
    $array = preg_split('/[\\n\\r]+/', $str);
    foreach ($array as $i => $value) {
        $prefix = " ";
        $val = str_startswith($value, $prefix);
        if ($val === true) {
        } else {
            $prefix = "ZZ";
            $val = str_startswith($value, $prefix);
            if ($val === true) {
            } else {
                include "dbitcon.php";
                //$query = "INSERT INTO COMS_Drugs (Drugs) VALUES ('$value')";
                $query = "INSERT INTO LookUp (Lookup_Type,Name,Description) VALUES (2,'{$value}','NLM')";
                $postDrugs = sqlsrv_query($conn, $query);
            }
        }
    }
    file_put_contents($myFile, "{$str}");
    echo "Text file created and database entries updated in Lookup table for LookupType 2.";
}
示例#26
0
function get_menu_entry()
{
    global $menu;
    $menu2 = $menu;
    // bug in php 5.1.6 (redhat 5.2)
    $page = get_current_page();
    $buffer_id = Null;
    $buffer_len = 0;
    foreach ($menu2 as $id => $entrie) {
        if (count($entrie['parent']) == 0) {
            continue;
        }
        if (!str_startswith($page, $entrie['page'])) {
            continue;
        }
        if (strlen($entrie['page']) > $buffer_len) {
            $buffer_id = $id;
            $buffer_len = strlen($entrie['page']);
        }
    }
    if ($buffer_id == Null) {
        $buffer_id = 'main';
    }
    return $buffer_id;
}