/**
 * Initialise the log browser and set up the menus.
 *
 */
function logbrowser_init()
{
    global $CONFIG;
    // Register a page handler, so we can have nice URLs
    register_page_handler('logbrowser', 'logbrowser_page_handler');
    // Extend CSS
    extend_view('css', 'logbrowser/css');
    // Extend context menu with admin logbrowsre link
    if (issuperadminloggedin()) {
        extend_view('profile/menu/adminlinks', 'logbrowser/adminlinks', 10000);
    }
}
function siteaccess_init()
{
    global $CONFIG;
    $CONFIG->disable_registration = false;
    if (siteaccess_walledgarden_enabled()) {
        if (!isloggedin()) {
            siteaccess_allowed_pages();
        }
    }
    register_plugin_hook('action', 'register', 'siteaccess_register_hook');
    register_plugin_hook('action', 'login', 'siteaccess_login_hook');
    register_plugin_hook('usersettings:save', 'user', 'siteaccess_user_settings_hook', 25);
    $period = get_plugin_setting('period', 'siteaccess');
    switch ($period) {
        case 'hourly':
        case 'daily':
        case 'weekly':
        case 'monthly':
            break;
        default:
            $period = 'weekly';
    }
    register_plugin_hook('cron', $period, 'siteaccess_cron_hook');
    if (issuperadminloggedin()) {
        register_page_handler('siteaccess', 'siteaccess_page_handler');
        // Add siteaccess/index.php
        extend_view('profile/menu/adminlinks', 'siteaccess/menu/siteaccess_adminlinks');
        // Add links to user profile
        register_action("siteaccess/activate", false, $CONFIG->pluginspath . "siteaccess/actions/activate.php", true);
        // Enable validate action
        register_action("siteaccess/email/save", false, $CONFIG->pluginspath . "siteaccess/actions/siteaccess/email/save.php", true);
        register_action("siteaccess/email/delete", false, $CONFIG->pluginspath . "siteaccess/actions/siteaccess/email/delete.php", true);
    }
    extend_view('css', 'siteaccess/css');
    register_action("siteaccess/confirm", true, $CONFIG->pluginspath . "siteaccess/actions/confirm.php");
    register_action("siteaccess/code", true, $CONFIG->pluginspath . "siteaccess/actions/code.php");
    register_elgg_event_handler('validate', 'user', 'siteaccess_validate_user');
    register_elgg_event_handler('create', 'user', 'siteaccess_create_user');
}
function superadmin_init()
{
    if (!issuperadminloggedin()) {
        register_page_handler('admin', 'superadmin_page_handler');
    }
}
// Add the form to this section
$nik = $_GET['id'];
$entity = get_entity($nik);
$query2 = "SELECT creator_guid FROM {$CONFIG->dbprefix}_content_item_discrimination WHERE guid = \"" . $nik . "\" and is_content_item = \"1\"";
$result2 = mysql_query($query2);
while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) {
    $nikolas = $row['creator_guid'];
}
$blah = get_entity($nikolas)->name;
if (issuperadminloggedin()) {
    $area2 .= "ORIGINAL OWNER:" . $blah . "<br />";
}
$query3 = "SELECT creator_guid FROM {$CONFIG->dbprefix}_content_item_discrimination WHERE guid = \"" . $_SESSION['user']->guid . "\" and is_content_item = \"1\"";
$result3 = mysql_query($query3);
while ($row = mysql_fetch_array($result3, MYSQL_ASSOC)) {
    $nikola1 = $row['creator_guid'];
}
if ($nikolas == $_SESSION['user']->guid || issuperadminloggedin() || $nikolas == $nikola1) {
    if (login($entity, FALSE)) {
        $area2 .= "You have succesfully logged in as:" . $entity->name . "<br />You can start socializing as this resource";
    } else {
        $area2 .= "Login failed";
    }
} else {
    $area2 .= "You don't have permission to assume the identity of this resource";
}
// layout the page
$body = elgg_view_layout('one_column', $area2);
//$body = elgg_view_layout('one_column', $area2);
// draw the page
page_draw($title, $body);
echo "</div>";
if ($exploratorysearch) {
    echo "Find additional results by clicking the checkbox of the items above you are most interested in";
}
echo "</div>";
echo "<script type='text/javascript'>setup_avatar_menu();</script>";
?>
	<script type="text/javascript">
		var base_url = '<?php 
echo $CONFIG->url;
?>
';
		var issuperadminloggedin;
		var exploratorysearch;
		if(<?php 
if (issuperadminloggedin()) {
    echo 1;
} else {
    echo 0;
}
?>
) issuperadminloggedin=1;
		else issuperadminloggedin=0;
		if(<?php 
if ($exploratorysearch) {
    echo 1;
} else {
    echo 0;
}
?>
) exploratorysearch=1;
<?php

/**
 * @package Elgg
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * @author Roger Curry, Grid Research Centre [curry@cpsc.ucalgary.ca]
 * @author Tingxi Tan, Grid Research Centre [txtan@cpsc.ucalgary.ca]
 * @link http://grc.ucalgary.ca/
 */
gatekeeper();
action_gatekeeper();
$guid = (int) get_input('compost');
$publication = get_entity($guid);
if ($publication->owner_guid == $_SESSION['guid'] || issuperadminloggedin()) {
    mysql_query("DELETE FROM elggentity_relationships WHERE guid_two='{$guid}' AND relationship='incoll' ");
    $rowsaffected = $publication->delete();
    if ($rowsaffected > 0) {
        system_message("Collection <b>DELETED</b>");
    } else {
        register_error("Collection cannot be deleted");
    }
    forward("mod/companion/");
}
 * 
 * @package ElggGroups
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * @author Curverider <*****@*****.**>
 * @copyright Curverider Ltd 2008-2009
 * @link http://elgg.org/
 */
// Ensure we're logged in
if (!isloggedin()) {
    forward();
}
// Make sure we can get the comment in question
$post_id = (int) get_input('post');
$group_guid = (int) get_input('group');
$topic_guid = (int) get_input('topic');
if ($post = get_annotation($post_id)) {
    //check that the user can edit as well as admin
    if (issuperadminloggedin() || $post->owner_guid == $_SESSION['user']->guid) {
        //delete
        $post->delete();
        //display confirmation message
        system_message(elgg_echo("grouppost:deleted"));
    }
} else {
    $url = "";
    system_message(elgg_echo("grouppost:notdeleted"));
}
// Forward to the group forum page
global $CONFIG;
$url = $CONFIG->wwwroot . "mod/groups/topicposts.php?topic={$topic_guid}&group_guid={$group_guid}";
forward($url);
" onclick="return confirm('Are you sure you want to make this user a superadmin?')" >MAKE SUPERADMIN</a></span>

									<span><?php 
            echo "page_owner=" . page_owner() . "," . "vars['user']->guid=" . $vars['user']->guid . ",page_owner_entity()->creatorg=" . page_owner_entity()->creatorg;
            ?>
 <span>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>  <?php 
        }
        ?>
                <!-- User Actions -->
		<?php 
        if (issuperadminloggedin() || page_owner() == $vars['user']->guid) {
            ?>

                <tr>
                    <td valign="top">
                        <table cellpadding="0" cellspacing="0" border="0" width="100%">
                            <tr>
                                <td class="txtAnnouncement" align="left">
                                    My Actions
                                </td>
                                <td>
                                    <span><a href="<?php 
            echo $vars['url'];
            ?>
pg/profile/<?php 
            echo $vars['entity']->username;
 */
// Load configuration
global $CONFIG;
gatekeeper();
$user_guid = get_input('user_guid');
if (!is_array($user_guid)) {
    $user_guid = array($user_guid);
}
$group_guid = get_input('group_guid');
if (sizeof($user_guid)) {
    foreach ($user_guid as $u_id) {
        $user = get_entity($u_id);
        $group = get_entity($group_guid);
        if ($user && $group) {
            //if (get_loggedin_userid() == $group->owner_guid)
            if ($group->owner_guid == $_SESSION['guid'] || issuperadminloggedin()) {
                // If the group is open or the user has requested membership
                if (check_entity_relationship($user->guid, 'membership_request', $group->guid) || $group->isPublicMembership()) {
                    if (!$group->isMember($user)) {
                        // Remove relationships
                        remove_entity_relationship($group->guid, 'invited', $user->guid);
                        remove_entity_relationship($user->guid, 'membership_request', $group->guid);
                        //add_entity_relationship($user->guid, 'member', $group->guid);
                        $group->join($user);
                        // send welcome email
                        notify_user($user->getGUID(), $group->owner_guid, sprintf(elgg_echo('groups:welcome:subject'), $group->name), sprintf(elgg_echo('groups:welcome:body'), $user->name, $group->name, $group->getURL()), NULL);
                        system_message(elgg_echo('groups:addedtogroup'));
                    } else {
                        register_error(elgg_echo("groups:cantjoin"));
                    }
                } else {
/**
 * A simple function to see who can edit a group discussion post
 * @param the comment $entity
 * @param user who owns the group $group_owner
 * @return boolean
 */
function groups_can_edit_discussion($entity, $group_owner)
{
    //logged in user
    $user = $_SESSION['user']->guid;
    if ($entity->owner_guid == $user || $group_owner == $user || issuperadminloggedin()) {
        return true;
    } else {
        return false;
    }
}
            echo '<p class="categories">' . $categories . '</p>';
        }
        ?>
			<div class="clearfloat"></div>
			<div class="blog_post_body">

			<!-- display the actual blog post -->
				<?php 
        echo elgg_view('output/longtext', array('value' => $vars['entity']->description));
        ?>
			</div><div class="clearfloat"></div>			
			<!-- display edit options if it is the blog post owner -->
			<p class="options">
			<?php 
        //		echo $vars[user]->guid."-".
        if (issuperadminloggedin() || $vars[user]->guid == $vars['entity']->owner_guid) {
            ?>
					<a href="<?php 
            echo $vars['url'];
            ?>
mod/blog/edit.php?blogpost=<?php 
            echo $vars['entity']->getGUID();
            ?>
"><?php 
            echo elgg_echo("edit");
            ?>
</a>  &nbsp; 
					<?php 
            echo elgg_view("output/confirmlink", array('href' => $vars['url'] . "action/blog/delete?blogpost=" . $vars['entity']->getGUID(), 'text' => elgg_echo('delete'), 'confirm' => elgg_echo('deleteconfirm')));
            // Allow the menu to be extended
            echo elgg_view("editmenu", array('entity' => $vars['entity']));
  </p>
<?php 
echo "<b>Tags: </b>";
echo elgg_view('output/tags', array('tags' => $vars['entity']->tags));
?>
<br /><br />
<p><?php 
$own = $vars['entity']->owner_guid;
$owner = get_entity($own);
echo "Created by: " . $owner->name;
?>
 </p>


<?php 
if ($vars['entity']->owner_guid == $_SESSION['guid'] || issuperadminloggedin()) {
    ?>

<div class="profile_info_edit_buttons">
<?php 
    echo elgg_view("output/confirmlink", array('href' => $vars['url'] . "action/companion/delete?compost=" . $vars['entity']->getGUID() . "&__elgg_ts=" . $ts . "&__elgg_token=" . $token, 'text' => "Delete ", 'confirm' => elgg_echo('deleteconfirm')));
    ?>
<a href="<?php 
    echo $vars['url'];
    ?>
mod/companion/edit.php?compost=<?php 
    echo $vars['entity']->getGUID();
    ?>
"><?php 
    echo "  Edit";
    ?>
    $user = $_SESSION['user'];
    set_page_owner($user->getGUID());
}
$query = "SELECT * FROM {$CONFIG->dbprefix}users_entity join {$CONFIG->dbprefix}_content_item_discrimination on {$CONFIG->dbprefix}users_entity.guid = {$CONFIG->dbprefix}_content_item_discrimination.guid and {$CONFIG->dbprefix}_content_item_discrimination.creator_guid = \"" . $_SESSION['id'] . "\"";
$result = get_data($query);
//echo $query;
$flag = false;
$total_users = count($result);
for ($i = 0; $i < $total_users; $i++) {
    $row = $result[$i];
    if ($row->guid == $selected_item) {
        $flag = true;
    }
}
///////////////
if ($user->guid == page_owner_entity()->creatorg || issuperadminloggedin() || $flag) {
    //3
    if ($title) {
        create_metadata($user->guid, 'meducator3', $title, 'text', $user->guid, $access_id);
        $user->name = $title;
    }
    //1
    if (is_array($urar)) {
        remove_metadata($user->guid, 'meducator1');
        $i = 0;
        foreach ($urar as $interval) {
            $i++;
            if ($i == 1) {
                $multiple = false;
            } else {
                $multiple = true;
/**
 * Used at the top of a page to mark it as logged in admin or siteadmin only.
 *
 */
function admin_gatekeeper()
{
    gatekeeper();
    if (!issuperadminloggedin()) {
        $_SESSION['last_forward_from'] = current_page_url();
        forward();
    }
}
    echo $advanced_search_criteria;
    ?>
		</table>

		<?php 
    echo elgg_view("input/submit", array("value" => elgg_echo("search")));
    echo " ";
    echo elgg_view("input/reset", array("value" => elgg_echo("reset")));
    ?>

		</form>
		</div>
		
		<?php 
}
if (issuperadminloggedin() && $exploratorysearch == 1) {
    //it adds the Cluster search panel
    ?>
		<div class="res_box1" id="cs" style="display:none">
		<h3 class='settings'><?php 
    echo elgg_echo("Cluster Search");
    ?>
</h3>
		<form id="clustersearch" action="javascript:void(0);" autocomplete="off">
			<?php 
    echo elgg_echo("Research type");
    echo "<br />";
    echo elgg_view("input/radio", array("id" => "type_id", "internalname" => "type", "value" => "clusterid", "options" => array(elgg_echo("By cluster id") => "clusterid", elgg_echo("By resources contained and/or pos. features") => "respf")));
    ?>
			<br />
			ID(s) cluster(s) (separated by ,)
<?php

/**
 * Elgg blog: delete post action
 * 
 * @package ElggBlog
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * @author Curverider Ltd <*****@*****.**>
 * @copyright Curverider Ltd 2008-2009
 * @link http://elgg.org/
 */
// Make sure we're logged in (send us to the front page if not)
gatekeeper();
// Get input data
$guid = (int) get_input('blogpost');
// Make sure we actually have permission to edit
$blog = get_entity($guid);
if ($blog->getSubtype() == "blog" && issuperadminloggedin() || $_SESSION['guid'] == $blog->owner_guid) {
    // Get owning user
    $owner = get_entity($blog->getOwner());
    // Delete it!
    $rowsaffected = $blog->delete();
    if ($rowsaffected > 0) {
        // Success message
        system_message(elgg_echo("blog:deleted"));
    } else {
        register_error(elgg_echo("blog:notdeleted"));
    }
    // Forward to the main blog page
    forward("mod/blog/?username=" . $owner->username);
}
    <p class="message_item_timestamp">
        <?php 
echo get_entity($vars['annotation']->owner_guid)->name . " " . friendly_time($vars['annotation']->time_created);
?>
    </p>
    		
	<!-- output the actual comment -->
	<div class="message"><?php 
echo elgg_view("output/longtext", array("value" => parse_urls($vars['annotation']->value)));
?>
</div>
	<div class="message_buttons">
		    
	<?php 
// if the user looking at the comment can edit, show the delete link
if (issuperadminloggedin() || $vars['user']->guid == $vars['annotation']->owner_guid) {
    echo "<div class='delete_message'>" . elgg_view("output/confirmlink", array('href' => $vars['url'] . "action/messageboard/delete?annotation_id=" . $vars['annotation']->id, 'text' => elgg_echo('delete'), 'confirm' => elgg_echo('deleteconfirm'))) . "</div>";
}
//end of can edit if statement
?>
		        <?php 
//if the message being looked at is owned by the current user, don't show the reply
if ($vars['annotation']->owner_guid != $_SESSION['guid']) {
    //get the message owner
    $get_entity = get_entity($vars['annotation']->owner_guid);
    //create the url to their messageboard
    $user_mb = "pg/messageboard/" . $get_entity->username;
    echo "<a href=\"" . $vars['url'] . $user_mb . "\">" . elgg_echo('messageboard:replyon') . " " . $get_entity->name . "'s " . elgg_echo('messageboard:messageboard') . "</a> | ";
    echo "<a href=\"" . $vars['url'] . "mod/messageboard/history.php?user="******"\">" . elgg_echo('messageboard:history') . "</a>";
}
?>
    }
    ?>
		
		<div class="filerepo_download"><p><a href="<?php 
    echo $vars['url'];
    ?>
action/file/download?file_guid=<?php 
    echo $file_guid;
    ?>
"><?php 
    echo elgg_echo("file:download");
    ?>
</a></p></div>
		
<?php 
    if (issuperadminloggedin() || $vars['user']->guid == $file->owner_guid) {
        ?>

	<div class="filerepo_controls">
				<p>
					<a href="<?php 
        echo $vars['url'];
        ?>
mod/file/edit.php?file_guid=<?php 
        echo $file->getGUID();
        ?>
"><?php 
        echo elgg_echo('edit');
        ?>
</a>&nbsp; 
					<?php 
<?php

/**
 * Elgg file delete
 * 
 * @package ElggFile
 * @author Curverider Ltd
 * @copyright Curverider Ltd 2008-2009
 * @link http://elgg.com/
 */
$guid = (int) get_input('file');
if ($file = get_entity($guid)) {
    if (issuperadminloggedin() || $_SESSION['guid'] == $file->owner_guid) {
        $container = get_entity($file->container_guid);
        $thumbnail = $file->thumbnail;
        $smallthumb = $file->smallthumb;
        $largethumb = $file->largethumb;
        if ($thumbnail) {
            $delfile = new ElggFile();
            $delfile->owner_guid = $file->owner_guid;
            $delfile->setFilename($thumbnail);
            $delfile->delete();
        }
        if ($smallthumb) {
            $delfile = new ElggFile();
            $delfile->owner_guid = $file->owner_guid;
            $delfile->setFilename($smallthumb);
            $delfile->delete();
        }
        if ($largethumb) {
            $delfile = new ElggFile();