function HookAction_datesPagestoolscron_copy_hitcountAddplugincronjob()
{
    global $lang, $action_dates_restrictfield, $action_dates_deletefield, $resource_deletion_state, $action_dates_reallydelete, $action_dates_email_admin_days, $email_notify, $email_from, $applicationname;
    $allowable_fields = sql_array("select ref as value from resource_type_field where type in (4,6,10)");
    # Check that this is a valid date field to use
    if (in_array($action_dates_restrictfield, $allowable_fields)) {
        $restrict_resources = sql_query("select resource, value from resource_data where resource_type_field = '{$action_dates_restrictfield}'");
        $emailrefs = array();
        foreach ($restrict_resources as $resource) {
            $ref = $resource["resource"];
            if ($action_dates_email_admin_days != "") {
                $action_dates_email_admin_seconds = intval($action_dates_email_admin_days) * 60 * 60 * 24;
                if (time() >= strtotime($resource["value"]) - $action_dates_email_admin_seconds && time() <= strtotime($resource["value"]) - $action_dates_email_admin_seconds + 86400) {
                    $emailrefs[] = $ref;
                }
            }
            if (time() >= strtotime($resource["value"])) {
                # Restrict access to the resource as date has been reached
                $existing_access = sql_value("select access as value from resource where ref='{$ref}'", "");
                if ($existing_access == 0) {
                    echo "restricting resource " . $ref . "\r\n";
                    sql_query("update resource set access=1 where ref='{$ref}'");
                    resource_log($ref, 'a', '', $lang['action_dates_restrict_logtext'], $existing_access, 1);
                }
            }
        }
        if (count($emailrefs) > 0) {
            global $baseurl;
            # Send email as the date is within the specified number of days
            $subject = $lang['action_dates_email_subject'];
            $message = str_replace("%%DAYS", $action_dates_email_admin_days, $lang['action_dates_email_text']) . "\r\n";
            $message .= $baseurl . "?r=" . implode("\r\n" . $baseurl . "?r=", $emailrefs) . "\r\n";
            $templatevars['message'] = $message;
            echo "Sending email to " . $email_notify . "\r\n";
            send_mail($email_notify, $subject, $message, $applicationname, $email_from, "emailexpiredresources", $templatevars, $applicationname);
        }
    }
    if (in_array($action_dates_deletefield, $allowable_fields)) {
        $delete_resources = sql_query("select resource, value from resource_data where resource_type_field = '{$action_dates_deletefield}'");
        foreach ($delete_resources as $resource) {
            $ref = $resource["resource"];
            if (time() >= strtotime($resource["value"])) {
                # Delete the resource as date has been reached
                echo "deleting resource " . $ref . "\r\n";
                if ($action_dates_reallydelete) {
                    delete_resource($ref);
                } else {
                    if (!isset($resource_deletion_state)) {
                        $resource_deletion_state = 3;
                    }
                    sql_query("update resource set archive='" . $resource_deletion_state . "' where ref='" . $ref . "'");
                }
                # Remove the resource from any collections
                sql_query("delete from collection_resource where resource='{$ref}'");
                resource_log($ref, 'x', '', $lang['action_dates_delete_logtext']);
            }
        }
    }
}
function HookAction_datesPagestoolscron_copy_hitcountAddplugincronjob()
	{
	global $lang, $action_dates_restrictfield,$action_dates_deletefield, $resource_deletion_state, $action_dates_reallydelete;
	
	
	$allowable_fields=sql_array("select ref as value from resource_type_field where type in (4,6,10)");
	# Check that this is a valid date field to use
	if(in_array($action_dates_restrictfield, $allowable_fields))
		{
		$restrict_resources=sql_query("select resource, value from resource_data where resource_type_field = '$action_dates_restrictfield'");
		
		foreach ($restrict_resources as $resource)
			{
			$ref=$resource["resource"];
			if (time()>=strtotime($resource["value"]))		
				{
				# Restrict access to the resource as date has been reached
				$existing_access=sql_value("select access as value from resource where ref='$ref'","");
				if($existing_access==0) # Only apply to resources that are currently open
					{
					echo "restricting resource " . $ref ."\r\n";
					sql_query("update resource set access=1 where ref='$ref'");
					resource_log($ref,'a','',$lang['action_dates_restrict_logtext'],$existing_access,1);		
					}
				}
			}
		}
	if(in_array($action_dates_deletefield, $allowable_fields))
		{
		$delete_resources=sql_query("select resource, value from resource_data where resource_type_field = '$action_dates_deletefield'");
		foreach ($delete_resources as $resource)
			{
			$ref=$resource["resource"];
			if (time()>=strtotime($resource["value"]))		
				{
				# Delete the resource as date has been reached
				echo "deleting resource " . $ref ."\r\n";
				if ($action_dates_reallydelete)
					{
					delete_resource($ref);
					}
				else
					{
					if (!isset($resource_deletion_state)){$resource_deletion_state=3;}
					sql_query("update resource set archive='" . $resource_deletion_state . "' where ref='" . $ref . "'");
					}
				# Remove the resource from any collections
				sql_query("delete from collection_resource where resource='$ref'");
				resource_log($ref,'x','',$lang['action_dates_delete_logtext']);			
				}	
			}
		}
	}
function alt_from_resource($source, $target, $name = '', $delete = false)
{
    // Copy a resource as an alt file of another resource
    // alt is the source resource, $ref is the target resource that will get the new alternate
    global $view_title_field;
    $srcdata = get_resource_data($source);
    $srcext = $srcdata['file_extension'];
    $srcpath = get_resource_path($source, true, "", false, $srcext);
    if ($name == '') {
        $name = sql_value("select value from resource_data where resource_type_field = '{$view_title_field}' and resource = '{$source}'", 'Untitled');
    }
    $description = '';
    if (!file_exists($srcpath)) {
        echo "ERROR: File not found.";
        return false;
    } else {
        $file_size = filesize_unlimited($srcpath);
        $altid = add_alternative_file($target, $name, $description = "", $file_name = "", $file_extension = "", $file_size, $alt_type = '');
        $newpath = get_resource_path($target, true, "", true, $srcext, -1, 1, false, '', $altid);
        copy($srcpath, $newpath);
        # Preview creation for alternative files (enabled via config)
        global $alternative_file_previews;
        if ($alternative_file_previews) {
            create_previews($target, false, $srcext, false, false, $altid);
        }
        if ($delete) {
            // we are supposed to delete the original resource when we're done
            # Not allowed to edit this resource? They shouldn't have been able to get here.
            if (!get_edit_access($source, $srcdata["archive"], false, $srcdata) || checkperm('D')) {
                exit("Permission denied.");
            } else {
                delete_resource($source);
            }
        }
        return true;
    }
}
 }
 if ($deleteall != "") {
     $deletecollection = $deleteall;
 }
 if (!function_exists("do_search")) {
     include "../include/search_functions.php";
 }
 if (!function_exists("delete_resource")) {
     include "../include/resource_functions.php";
 }
 # Delete all resources in collection
 if (!checkperm("D")) {
     $resources = do_search("!collection" . $deletecollection);
     for ($n = 0; $n < count($resources); $n++) {
         if (checkperm("e" . $resources[$n]["archive"])) {
             delete_resource($resources[$n]["ref"]);
             collection_log($deletecollection, "D", $resources[$n]["ref"]);
         }
     }
 }
 if ($purge != "") {
     # Delete collection
     delete_collection($purge);
     # Get count of collections
     $c = get_user_collections($userref);
     # If the user has just deleted the collection they were using, select a new collection
     if ($usercollection == $purge && count($c) > 0) {
         # Select the first collection in the dropdown box.
         $usercollection = $c[0]["ref"];
         set_user_collection($userref, $usercollection);
     }
Exemplo n.º 5
0
function save_collection($ref)
	{
	global $theme_category_levels;
	
	
	$allow_changes=(getval("allow_changes","")!=""?1:0);
	
	# Next line disabled as it seems incorrect to override the user's setting here. 20071217 DH.
	#if ($theme!="") {$allow_changes=0;} # lock allow changes to off if this is a theme
	
	# Update collection with submitted form data
	if (!hook('modifysavecollection')) {
	$sql="update collection set
				name='" . getvalescaped("name","") . "',
				keywords='" . getvalescaped("keywords","") . "',
				public='" . getvalescaped("public","",true) . "',";
		
		for($n=1;$n<=$theme_category_levels;$n++){
			if ($n==1){$themeindex="";} else {$themeindex=$n;}
			$themes[$n]=getvalescaped("theme$themeindex","");
			if (getval("newtheme$themeindex","")!="") {
				$themes[$n]=trim(getvalescaped("newtheme$themeindex",""));
				}
			if (isset($themes[$n])){
				$sql.="theme".$themeindex."='" . $themes[$n]. "',";
				}
		}

	$sql.="allow_changes='" . $allow_changes . "'";
	
	if (checkperm("h"))
		{	
		$sql.="
			,home_page_publish='" . (getvalescaped("home_page_publish","")!=""?"1":"0") . "'
			,home_page_text='" . getvalescaped("home_page_text","") . "'";
		if (getval("home_page_image","")!="")
			{
			$sql.=",home_page_image='" . getvalescaped("home_page_image","") . "'";
			}
		}
		
	    $sql.=" where ref='$ref'";
	
	sql_query($sql);
	} # end replace hook - modifysavecollection
	
	index_collection($ref);
		
	# If 'users' is specified (i.e. access is private) then rebuild users list
	$users=getvalescaped("users",false);
	if ($users!==false)
		{
		sql_query("delete from user_collection where collection='$ref'");
		#log this
		collection_log($ref,"T",0, '#all_users');

		if (($users)!="")
			{
			# Build a new list and insert
			$users=resolve_userlist_groups($users);
			$ulist=array_unique(trim_array(explode(",",$users)));
			$urefs=sql_array("select ref value from user where username in ('" . join("','",$ulist) . "')");
			if (count($urefs)>0)
				{
				sql_query("insert into user_collection(collection,user) values ($ref," . join("),(" . $ref . ",",$urefs) . ")");
				}
			#log this
			collection_log($ref,"S",0, join(", ",$ulist));
			}
		}
		
	# Relate all resources?
	if (getval("relateall","")!="")
		{
		$rlist=get_collection_resources($ref);
		for ($n=0;$n<count($rlist);$n++)
			{
			for ($m=0;$m<count($rlist);$m++)
				{
				if ($rlist[$n]!=$rlist[$m]) # Don't relate a resource to itself
					{
					sql_query("delete from resource_related where resource='" . $rlist[$n] . "' and related='" . $rlist[$m] . "'");
					sql_query("insert into resource_related (resource,related) values ('" . $rlist[$n] . "','" . $rlist[$m] . "')");
					}
				}
			}
		}
	
	
	# Remove all resources?
	if (getval("removeall","")!="")
		{
		remove_all_resources_from_collection($ref);
		}
		
	# Delete all resources?
	if (getval("deleteall","")!="" && !checkperm("D"))
		{
		$resources=do_search("!collection" . $ref);
		for ($n=0;$n<count($resources);$n++)
			{
			if (checkperm("e" . $resources[$n]["archive"]))
				{
				delete_resource($resources[$n]["ref"]);	
				collection_log($ref,"D",$resources[$n]["ref"]);
				}
			}
		}
		
	# Update limit count for saved search
	if (isset($_POST["result_limit"]))
		{
		sql_query("update collection_savedsearch set result_limit='" . getvalescaped("result_limit","") . "' where collection='$ref'");
		
		}
	
	refresh_collection_frame();
	}
Exemplo n.º 6
0
function update_resource($r,$path,$type,$title,$ingest=false)
	{
	# Update the resource with the file at the given path
	# Note that the file will be used at it's present location and will not be copied.
	global $syncdir,$staticsync_prefer_embedded_title;

	update_resource_type($r, $type);

	# Work out extension based on path
	$extension=explode(".",$path);$extension=trim(strtolower(end($extension)));

	# file_path should only really be set to indicate a staticsync location. Otherwise, it should just be left blank.
	if ($ingest){$file_path="";} else {$file_path=escape_check($path);}

	# Store extension/data in the database
	sql_query("update resource set archive=0,file_path='".$file_path."',file_extension='$extension',preview_extension='$extension',file_modified=now() where ref='$r'");

	# Store original filename in field, if set
	if (!$ingest)
		{
		# This file remains in situ; store the full path in file_path to indicate that the file is stored remotely.
		global $filename_field;
		if (isset($filename_field))
			{

			$s=explode("/",$path);
			$filename=end($s);

			update_field($r,$filename_field,$filename);
			}
		}
	else
		{
		# This file is being ingested. Store only the filename.
		$s=explode("/",$path);
		$filename=end($s);

		global $filename_field;
		if (isset($filename_field))
			{
			update_field($r,$filename_field,$filename);
			}

		# Move the file
		global $syncdir;
		$destination=get_resource_path($r,true,"",true,$extension);
		$result=rename($syncdir . "/" . $path,$destination);
		if ($result===false)
			{
			# The rename failed. The file is possibly still being copied or uploaded and must be ignored on this pass.
			# Delete the resouce just created and return false.
			delete_resource($r);
			return false;
			}
		chmod($destination,0777);
		}

	# generate title and extract embedded metadata
	# order depends on which title should be the default (embedded or generated)
	if ($staticsync_prefer_embedded_title)
		{
		update_field($r,8,$title);
		extract_exif_comment($r,$extension);
	} else {
		extract_exif_comment($r,$extension);
		update_field($r,8,$title);
	}


	# Ensure folder is created, then create previews.
	get_resource_path($r,false,"pre",true,$extension);

	# Generate previews/thumbnails (if configured i.e if not completed by offline process 'create_previews.php')
	global $enable_thumbnail_creation_on_upload;
	if ($enable_thumbnail_creation_on_upload) {create_previews($r,false,$extension);}

	# Pass back the newly created resource ID.
	return $r;
	}
function delete_resources_in_collection($collection)
{
    global $resource_deletion_state;
    // Always find all resources in deleted state and delete them permanently:
    // Note: when resource_deletion_state is null it will find all resources in collection and delete them permanently
    $query = sprintf("\n\t\t\t\tSELECT ref AS value\n\t\t\t\t  FROM resource\n\t\t\tINNER JOIN collection_resource ON collection_resource.resource = resource.ref AND collection_resource.collection = '%s'\n\t\t\t\t %s;\n\t", $collection, isset($resource_deletion_state) ? "WHERE archive = '" . $resource_deletion_state . "'" : '');
    $resources_in_deleted_state = array();
    $resources_in_deleted_state = sql_array($query);
    if (!empty($resources_in_deleted_state)) {
        foreach ($resources_in_deleted_state as $resource_in_deleted_state) {
            delete_resource($resource_in_deleted_state);
        }
        collection_log($collection, 'D', '', 'Resource ' . $resource_in_deleted_state . ' deleted permanently.');
    }
    // Create a comma separated list of all resources remaining in this collection:
    $resources = sql_array("SELECT resource AS value FROM collection_resource WHERE collection = '" . $collection . "';");
    $resources = implode(',', $resources);
    // If all resources had their state the same as resource_deletion_state, stop here:
    // Note: when resource_deletion_state is null it will always stop here
    if (empty($resources)) {
        return TRUE;
    }
    // Delete (ie. move to resource_deletion_state set in config):
    if (isset($resource_deletion_state)) {
        $query = sprintf("\n\t\t\t\t    UPDATE resource\n\t\t\t\tINNER JOIN collection_resource ON collection_resource.resource = resource.ref AND collection_resource.collection = '%s'\n\t\t\t\t       SET archive = '%s';\n\t\t", $collection, $resource_deletion_state);
        sql_query($query);
        collection_log($collection, 'D', '', 'All resources of this collection have been deleted by moving them to state ' . $resource_deletion_state);
        $query = sprintf("\n\t\t\t\tDELETE FROM collection_resource \n\t\t\t\t      WHERE resource IN (%s);\n\t\t", $resources);
        sql_query($query);
    }
    return TRUE;
}
include "../../include/db.php";
include "../../include/general.php";
include "../../include/resource_functions.php";
include "../../include/image_processing.php";
// restore the default system error handler
// so that we can handle things like permission errors
// on our own.
restore_error_handler();
// make darn sure the user knows what they are doing!
echo "\nResourceSpace Purge Script\n\n";
echo "   This script will purge all files marked for deletion\n";
echo "   in the system. This is permanent, and cannot be undone\n";
echo "   \n\n";
echo "WARNING: THIS SCRIPT IS DANGEROUS AND MAY PERMANENTLY DELETE A LARGE NUMBER OF FILES!\nContinue at your own risk!\n";
echo "Are you sure you want to do this? Type \"yes\" to continue: \n> ";
$line = trim(fgets(STDIN));
if (strtolower($line) != 'yes') {
    echo "Aborting...\n";
    exit;
}
echo "\n------------------------------------------------------------\n";
// override resource deletion state
unset($resource_deletion_state);
$topurge = sql_array("select ref as value from resource where archive = '3'");
$purgecount = 0;
foreach ($topurge as $ref) {
    echo "Purging {$ref}\n";
    delete_resource($ref);
    $purgecount++;
}
echo "\n\nComplete. {$purgecount} resources purged.\n\n";
Exemplo n.º 9
0
    $keywords = $_POST['keywords'];
}
if (isset($_GET['keywords'])) {
    $keywords = $_GET['keywords'];
}
$user_id = $_SESSION[id];
// Calculate pagination information
$cur_page = isset($_GET['page']) ? $_GET['page'] : 1;
$results_per_page = 10;
// number of results per page
$skip = ($cur_page - 1) * $results_per_page;
$total = get_total($keywords, $user_id, $dbc);
$num_pages = ceil($total / $results_per_page);
if (isset($_GET['deleted_file'])) {
    $deleted_file = get_title_by_id($dbc, $_GET['deleted_file']);
    delete_resource($dbc, $db_name, $_GET['deleted_file']);
    //echo '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">&times;</button>';
    //echo '文献"' . $deleted_file . '"已被删除!</div>';
    render_success('文献"' . $deleted_file . '"已被删除!');
}
?>
<p></p>
<div class="container">
    <?php 
include_once 'resource_header.php';
?>
    <table class="table table-hover">
        <tbody>
            <tr class="info">
                <td>#</td>
                <td ><strong>创建者</strong></td>
Exemplo n.º 10
0
        search_content();
        break;
    case 'search2':
        search2();
        break;
    case 'viewmatrix':
        viewmatrix();
        break;
    case 'create':
        create_new();
        break;
    case 'create2':
        create_confirm();
        break;
    case 'delete_resource':
        delete_resource();
        break;
}
function viewmatrix()
{
    global $db;
    do_form_header('rcm_matrix.php');
    generate_matrix($_REQUEST['type']);
}
function create_new()
{
    global $db;
    do_form_header('rcm_matrix.php');
    do_table_header('Create New Relational Link');
    if ($_REQUEST['reltype'] == 'news') {
        do_news_row();
Exemplo n.º 11
0
    // Debug
    // printJson(array(
    //   'last-synced' => $lastSync,
    //   'RS last Modified' => $rsLastModified,
    //   'RS string' => $lastModified,
    //    'has New Version' => $hasNewVersion
    // ));
}
// DELETE
// ============================================================
// - delete file from collection
// - delete collection and all files in the collection
// ============================================================
// delete file
if ($delete_file && $file_id) {
    delete_resource($file_id);
    printJson(true);
}
// delete collection and all files in the collection
if ($delete_collection && $collection_id) {
    $delete = delete_collection($collection_id);
    printJson($delete);
}
// CREATE
// ============================================================
// - create a new collection
// ============================================================
// create a new collection
// returns id of new collection
if ($create_collection && $collection_name && $user_id) {
    $allowchanges = 1;