コード例 #1
0
ファイル: user.api.php プロジェクト: rentasite/drupal
/**
 * Act on user account cancellations.
 *
 * The user account is being canceled. Depending on the account cancellation
 * method, the module should either do nothing, unpublish content, anonymize
 * content, or delete content and data belonging to the canceled user account.
 *
 * Expensive operations should be added to the global batch with batch_set().
 *
 * @param $edit
 *   The array of form values submitted by the user.
 * @param $account
 *   The user object on which the operation is being performed.
 * @param $method
 *   The account cancellation method.
 *
 * @see user_cancel_methods()
 * @see hook_user_cancel_methods_alter()
 * @see user_cancel()
 */
function hook_user_cancel($edit, $account, $method)
{
    switch ($method) {
        case 'user_cancel_block_unpublish':
            // Unpublish nodes (current revisions).
            module_load_include('inc', 'node', 'node.admin');
            $nodes = db_select('node', 'n')->fields('n', array('nid'))->condition('uid', $account->uid)->execute()->fetchCol();
            node_mass_update($nodes, array('status' => 0));
            break;
        case 'user_cancel_reassign':
            // Anonymize nodes (current revisions).
            module_load_include('inc', 'node', 'node.admin');
            $nodes = db_select('node', 'n')->fields('n', array('nid'))->condition('uid', $account->uid)->execute()->fetchCol();
            node_mass_update($nodes, array('uid' => 0));
            // Anonymize old revisions.
            db_update('node_revision')->fields(array('uid' => 0))->condition('uid', $account->uid)->execute();
            // Clean history.
            db_delete('history')->condition('uid', $account->uid)->execute();
            break;
        case 'user_cancel_delete':
            // Delete nodes (current revisions).
            $nodes = db_select('node', 'n')->fields('n', array('nid'))->condition('uid', $account->uid)->execute()->fetchCol();
            foreach ($nodes as $nid) {
                node_delete($nid);
            }
            // Delete old revisions.
            db_delete('node_revision')->condition('uid', $account->uid)->execute();
            // Clean history.
            db_delete('history')->condition('uid', $account->uid)->execute();
            break;
    }
}
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function tearDown()
 {
     parent::tearDown();
     foreach ($this->nodes as $node) {
         node_delete($node->nid);
     }
 }
コード例 #3
0
ファイル: CiviCRM.php プロジェクト: kidaa30/yes
 /**
  * @param int $groupID
  * @param $group
  */
 public static function groupDelete($groupID, $group)
 {
     $ogID = CRM_Bridge_OG_Utils::ogID($groupID, FALSE);
     if (!$ogID) {
         return;
     }
     node_delete($ogID);
 }
コード例 #4
0
 function tearDown()
 {
     while (sizeof($this->_cleanupGroups) > 0) {
         $gid = array_pop($this->_cleanupGroups);
         node_delete($gid);
     }
     parent::tearDown();
 }
コード例 #5
0
 public function testCreateNode()
 {
     $this->loginAsAdmin();
     $node = $this->drupalCreateNode(array('uid' => 1, 'language' => 'en'));
     $this->assertNotNull($node);
     $this->assertTrue($node->nid > 0);
     node_delete($node->nid);
 }
コード例 #6
0
ファイル: CiviCRM.php プロジェクト: hampelm/Ginsberg-CiviDemo
 static function groupDelete($groupID, $group)
 {
     require_once 'CRM/Bridge/OG/Utils.php';
     $ogID = CRM_Bridge_OG_Utils::ogID($groupID, false);
     if (!$ogID) {
         return;
     }
     node_delete($ogID);
 }
    public function apply ( $patients ) {
        if ( !is_array($patients) ) {
            $patients = array($patients);
        }

        foreach ( $patients as $patient ) {
            \LogHelper::log_info('Applying DeleteReport treatment to: '.$patient->reportNodeId);
            node_delete($patient->reportNodeId);
        }
    }
コード例 #8
0
 public function test_osha_workflow_get_set_project_manager()
 {
     $this->assertNull(osha_workflow_get_project_manager(-1));
     $node = $this->createNodeNews();
     $pm3 = user_load_by_name('project_manager3');
     osha_workflow_set_project_manager($node->nid, $pm3->uid);
     $pm = osha_workflow_get_project_manager($node->nid);
     $this->assertEquals($pm3->uid, $pm->uid);
     $this->assertFalse(osha_workflow_is_assigned_project_manager($node->nid));
     $this->loginAs('project_manager3');
     $this->assertTrue(osha_workflow_is_assigned_project_manager($node->nid));
     node_delete($node->nid);
 }
コード例 #9
0
ファイル: og_testcase.php プロジェクト: sdboyer/sdboyer-test
 function tearDown()
 {
     while (sizeof($this->_cleanupGroups) > 0) {
         $gid = array_pop($this->_cleanupGroups);
         node_delete($gid);
     }
     include_once './' . drupal_get_path('module', 'node') . '/content_types.inc';
     while (sizeof($this->_cleanupNodeTypes) > 0) {
         $name = array_pop($this->_cleanupNodeTypes);
         node_type_delete_confirm_submit(0, array('name' => $name, 'type' => $name));
     }
     parent::tearDown();
 }
    public function apply ( $patients ) {
        if ( !is_array($patients) ) {
            $patients = array($patients);
        }

        foreach ( $patients as $patient ) {
            \LogHelper::log_info('Applying DeleteDataset treatment to: '.$patient->datasetNodeId);
            // remove columns
            $columnNodeIds = gd_column_get_columns_4_dataset($patient->datasetNodeId, LOAD_ENTITY_ID_ONLY, INCLUDE_UNPUBLISHED);
            if ( !empty($columnNodeIds) ) {
                node_delete_multiple($columnNodeIds);
            }
            node_delete($patient->datasetNodeId);
        }
    }
コード例 #11
0
 public function xxtestUserCanEditApprovers()
 {
     global $user;
     $user = user_load(1);
     $node = $this->drupalCreateNode(array('type' => 'news', 'language' => 'en', 'uid' => 1, 'title' => 'TEST NODE'));
     $user = user_load(0);
     $this->assertFalse(OshaWorkflowPermissions::userCanAccessApprovalScreen($node, NULL));
     $this->assertFalse(OshaWorkflowPermissions::userCanAccessApprovalScreen((object) array(), $user));
     $user = user_load(1);
     $this->assertTrue(OshaWorkflowPermissions::userCanAccessApprovalScreen($node, $user));
     $user = user_load_by_name('review_manager1');
     $this->assertTrue(OshaWorkflowPermissions::userCanAccessApprovalScreen($node, $user));
     $this->drupalLogout();
     node_delete($node->nid);
 }
コード例 #12
0
 /**
  * Delete a node.
  */
 protected function deleteNode($nid)
 {
     // Implemention taken from node_delete, with some assumptions regarding
     // function_exists removed.
     node_delete($nid);
     //    $node = node_load($nid);
     //    db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
     //    db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);
     //
     //    // Call the node-specific callback (if any):
     //    node_invoke($node, 'delete');
     //    node_invoke_nodeapi($node, 'delete');
     //
     //    // Clear the page and block caches.
     //    cache_clear_all();
 }
コード例 #13
0
function bootstrap_theme_delete_collection($collection_id)
{
    $node = node_load($collection_id);
    if (!empty($node)) {
        node_delete($collection_id);
    }
    return '<div id="dashboard_a_collections">' . _bootstrap_theme_collections_html() . '</div>';
}
コード例 #14
0
 /**
  * Delete the current entity from the database.
  */
 public function delete()
 {
     if ($this->getEntityType() == 'node') {
         node_delete($this->get('nid'));
     } else {
         entity_delete($this->getEntityType(), $this->get('id'));
     }
 }
コード例 #15
0
 public function deleteFolder($filedepot_folder_id)
 {
     /* Test for valid folder and admin permission one more time
      * We are going to override the permission test in the function filedepot_getRecursiveCatIDs()
      * and return all subfolders in case hidden folders exist for this user.
      * If this user has admin permission for parent -- then they should be able to delete it
      * and any subfolders.
      */
     if ($filedepot_folder_id > 0 and $this->checkPermission($filedepot_folder_id, 'admin')) {
         // Need to delete all files in the folder
         /* Build an array of all linked categories under this category the user has admin access to */
         $list = array();
         array_push($list, $filedepot_folder_id);
         // Passing in permission check over-ride as noted above to filedepot_getRecursiveCatIDs()
         $list = $this->getRecursiveCatIDs($list, $filedepot_folder_id, 'admin', TRUE);
         foreach ($list as $cid) {
             // Drupal will remove the file attachments automatically when folder node is deleted even if file usage is > 1
             $query = db_query("SELECT drupal_fid FROM {filedepot_files} WHERE cid=:cid", array(':cid' => $cid));
             while ($A = $query->fetchAssoc()) {
                 $file = file_load($A['drupal_fid']);
                 file_usage_delete($file, 'filedepot');
                 if (file_exists($file->uri)) {
                     file_delete($file);
                 }
             }
             $subfolder_nid = db_query("SELECT nid FROM {filedepot_categories} WHERE cid=:cid", array(':cid' => $cid))->fetchField();
             db_delete('filedepot_categories')->condition('cid', $cid)->execute();
             db_delete('filedepot_categories')->condition('cid', $cid)->execute();
             db_delete('filedepot_access')->condition('catid', $cid)->execute();
             db_delete('filedepot_recentfolders')->condition('cid', $cid)->execute();
             db_delete('filedepot_notifications')->condition('cid', $cid)->execute();
             db_delete('filedepot_filesubmissions')->condition('cid', $cid)->execute();
             // Call the drupal node delete now for the subfolder node
             //watchdog('filedepot',"Calling node_delete for node id: {$subfolder_nid}");
             node_delete($subfolder_nid);
             // Remove the physical directory
             $uri = $this->root_storage_path . $cid;
             if (file_exists($uri)) {
                 $ret = @unlink("{$uri}/.htaccess");
                 $ret = @unlink("{$uri}/submissions/.htaccess");
                 $ret = @drupal_rmdir("{$uri}/submissions");
                 $ret = @drupal_rmdir($uri);
             }
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }
コード例 #16
0
ファイル: remove_invalid.php プロジェクト: brainsum/memosaic
<?php

$result = db_query("SELECT entity_id FROM `field_data_field_obec` WHERE `field_obec_value` LIKE 'Slovakia,%%' AND entity_type='node'");
foreach ($result as $record) {
    echo $record->entity_id . "\n";
    node_delete($record->entity_id);
}
コード例 #17
0
 /**
  * @Given Valghalla testdata is available
  */
 public function valghallaTestdataIsAvailable()
 {
     // @Todo
     $query = new EntityFieldQuery();
     $query->entityCondition('entity_type', 'node')->propertyCondition('title', 'Test Deltager No-Mail');
     $result = $query->execute();
     if (isset($result['node'])) {
         node_delete(key($result['node']));
     }
     $node = (object) array('vid' => NULL, 'uid' => '1', 'title' => 'Test Deltager No-Mail', 'log' => '', 'status' => '1', 'comment' => '0', 'promote' => '1', 'sticky' => '0', 'nid' => NULL, 'type' => 'volunteers', 'language' => 'da', 'created' => '1428566112', 'changed' => '1428568628', 'tnid' => '0', 'translate' => '0', 'revision_timestamp' => '1428568628', 'revision_uid' => '1', 'field_address_bnummer' => array(), 'field_address_city' => array(), 'field_address_coname' => array(), 'field_address_door' => array(), 'field_address_floor' => array(), 'field_address_road' => array(), 'field_address_road_no' => array(), 'field_address_zipcode' => array(), 'field_cpr_number' => array('da' => array(array('value' => '123456-1213', 'format' => NULL, 'safe_value' => '123456-1213'))), 'field_cpr_valid_date' => array(), 'field_diaet' => array('da' => array(array('value' => '750'))), 'field_email' => array('da' => array(array('email' => '*****@*****.**'))), 'field_label' => array(), 'field_party' => array('da' => array(array('tid' => '3'))), 'field_phone' => array('da' => array(array('value' => '0', 'format' => NULL, 'safe_value' => '0'))), 'field_phone2' => array(), 'field_polling_station' => array(), 'field_polling_station_post' => array(), 'field_rolle_id' => array(), 'field_meeting_time' => array(), 'field_ending_time' => array(), 'field_cpr_status' => array(), 'field_external_signup' => array('und' => array(array('value' => '0'))), 'field_valid_state' => array('und' => array(array('value' => 'invalid'))), 'field_volunteer_valid_date' => array('und' => array(array('value' => '2015-04-09 08:00:00', 'timezone' => 'Europe/Copenhagen', 'timezone_db' => 'UTC', 'date_type' => 'datetime'))), 'field_no_mail' => array('und' => array(array('value' => 1))), 'name' => 'admin', 'picture' => '0', 'data' => 'a:7:{s:7:"contact";i:1;s:16:"ckeditor_default";s:1:"t";s:20:"ckeditor_show_toggle";s:1:"t";s:14:"ckeditor_width";s:4:"100%";s:13:"ckeditor_lang";s:2:"en";s:18:"ckeditor_auto_lang";s:1:"t";s:17:"mimemail_textonly";i:0;}');
     node_save($node);
     $volunteer_no_mail_nid = $node->nid;
     return TRUE;
 }
コード例 #18
0
 /**
  * Deletes a text
  *
  * @param int $nid ["path","0"]
  *  The nid of the text to delete
  * @return bool
  *
  * @Access(callback='DocuWalkTextResource::access', args={'delete'}, appendArgs=true)
  */
 public static function delete($nid)
 {
     node_delete($nid);
 }
コード例 #19
0
function cleanup_DeleteDuplicateExportArticles($printDebugReport = false, $param = 50)
{
    $ret = array();
    $query = "\n        SELECT n1.title as 'Title',\n        count(n1.title) as 'Count',\n        GROUP_CONCAT(n1.nid) as 'nodeIds'\n        FROM  node n1\n        WHERE n1.type='export_gov_micro_site_page' AND n1.status=1\n        GROUP BY n1.title\n        HAVING count(n1.title) > 1 LIMIT " . $param . ";";
    $results = db_query($query);
    foreach ($results as $result) {
        $duplicateNids = explode(',', $result->nodeIds);
        foreach ($duplicateNids as $index => $dupNodeId) {
            if ($index === 0) {
                // This is the first Node of its kind, do not delete this one
                $firstEventOfItsKind = $dupNodeId;
            } else {
                // This is not the first Node of its kind, delete this one
                $ret[] = $dupNodeId;
                node_delete($dupNodeId);
                $msg = __FILE__ . '::' . __FUNCTION__ . " - Deleted Export Articles node {$dupNodeId} because it is a duplicate of node {$firstEventOfItsKind}. Title={$result->Title}";
                error_log($msg);
                if ($printDebugReport) {
                    drupal_set_message($msg, 'warning');
                }
            }
        }
    }
    return $ret;
}
コード例 #20
0
 public function save($nid_parkauto, $sop_selected, $user_nid)
 {
     // elimina tutti i CT sop presenti con il nid.
     if ($nid_parkauto) {
         $query = new EntityFieldQuery();
         $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'servizi_opzionali_planning')->propertyCondition('status', 1)->fieldCondition('field_sop_nid_parkauto', 'value', $nid_parkauto)->addMetaData('account', user_load(1));
         $qryres = $query->execute();
         if (isset($qryres['node'])) {
             $items_nids = array_keys($qryres['node']);
             foreach ($items_nids as $knode => $vnode) {
                 node_delete($vnode);
             }
         }
     }
     if (gettype($sop_selected) != 'object') {
         $xdebug = 1;
     }
     $ar = get_object_vars($sop_selected);
     if (empty($ar)) {
         return;
     }
     // Ricrea i nuovi nodi
     foreach ($sop_selected as $k => $elem) {
         if ($elem->{'nid_parkauto'}) {
             $this->build_new_node('servizi_opzionali_planning', $elem, $user_nid);
         }
     }
 }
コード例 #21
0
            $i++;
        }
    }
    //NON PO
    $results_nonpo = db_query('SELECT n.nid FROM {node} n 
		LEFT JOIN {field_data_field_nonpo_sync_status} pss ON pss.entity_id = n.nid 
		WHERE n.type = :type 
			AND (pss.field_nonpo_sync_status_value != :sync_status OR n.uid = :uid) 
			AND DATE(FROM_UNIXTIME(n.created)) <= DATE_SUB(NOW(), INTERVAL :intervaldays DAY)', array('type' => 'non_po', 'sync_status' => 1, 'uid' => 0, 'intervaldays' => $intervaldays))->fetchAll();
    if ($results_nonpo) {
        foreach ($results_nonpo as $nonpo) {
            node_delete($nonpo->nid);
            $i++;
        }
    }
    //BIR
    $results_bir = db_query('SELECT n.nid FROM {node} n 
		LEFT JOIN {field_data_field_bir_sync_status} pss ON pss.entity_id = n.nid 
		WHERE n.type = :type 
			AND (pss.field_bir_sync_status_value != :sync_status OR n.uid = :uid) 
			AND DATE(FROM_UNIXTIME(n.created)) <= DATE_SUB(NOW(), INTERVAL :intervaldays DAY)', array('type' => 'bir', 'sync_status' => 1, 'uid' => 0, 'intervaldays' => $intervaldays))->fetchAll();
    if ($results_bir) {
        foreach ($results_bir as $bir) {
            node_delete($bir->nid);
            $i++;
        }
    }
    if ($i != 0) {
        drupal_set_message(t('Deleted @record_number record(s) successfully.', array('@record_number' => $i)), 'status');
    }
}
コード例 #22
0
ファイル: app.php プロジェクト: rubensayshi/nodejssync
<?php 
error_reporting(E_ALL);
ini_set('display_errors', 'On');

if (isset($_GET['action']) && $_GET['action'] == 'new' && $_SERVER['REQUEST_METHOD'] == 'POST') {
	$node = array('title' => $_POST['title'], 'body' => $_POST['body'], 'created' => time());
	node_insert($node);
}

if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['_id'])) {
	node_delete($_GET['_id']);
}

// find everything in the collection
$nodes = getMyDB()->nodes->find();

if (isset($_GET['action']) && $_GET['action'] == 'sync') {
	foreach ($nodes as $node) {
		node_sync('insert', $node);
	}
}
コード例 #23
0
ファイル: kentry.module.Test.php プロジェクト: jgosier/kamusi
 public function teardown()
 {
     node_delete($this->node1->nid);
     db_query('TRUNCATE {kdictionary}');
     db_query('TRUNCATE {kentry}');
 }
コード例 #24
0
ファイル: cleanup.php プロジェクト: NRHWorks/jobs
<?php

/*
$now = time();

$cutoff = $now - 1814400;

print "$now - $cutoff\n";

$count = db_query("SELECT count(*) FROM node WHERE created < $cutoff")->fetchField();

print "Deleting: $count nodes\n==============================\n";

$result = db_query("SELECT nid, title FROM node WHERE type = 'lead'");

foreach ($result as $r) {
  print "Deleting: ({$r->nid}) {$r->title} \n";
  node_delete($r->nid);
}
*/
$count = db_query("SELECT count(*) FROM node WHERE type = 'lead'")->fetchField();
print "Deleting: {$count} nodes\n==============================\n";
$result = db_query("SELECT nid, title FROM node WHERE type = 'lead'");
foreach ($result as $r) {
    print "Deleting: ({$r->nid}) {$r->title} \n";
    node_delete($r->nid);
}
コード例 #25
0
ファイル: Drupal7.php プロジェクト: ian-yin/drupalextension
 /**
  * {@inheritDoc}
  */
 public function nodeDelete($node)
 {
     node_delete($node->nid);
 }
コード例 #26
0
ファイル: FeatureContext.php プロジェクト: aleph-n/opencholar
 /**
  * @Given /^I delete the node "([^"]*)"$/
  */
 public function iDeleteTheNode($title)
 {
     $nid = FeatureHelp::getNodeId($title);
     node_delete($nid);
 }
コード例 #27
0
#!/usr/bin/env drush
<?php 
include 'sphsc-helpers.php';
node_delete(272);
sphsc1();
return;
function sphsc1()
{
    $query = db_select('node', 'n')->fields('n')->condition('n.type', 'page')->orderBy('n.nid', 'desc');
    $qresult = $query->execute()->fetchAll();
    foreach ($qresult as $k => $data) {
        print "\n#####" . $data->nid . "|" . $data->type . "|" . $data->title;
        $node = node_load($data->nid);
        print empty($node->nid) ? "\n\tMISS:" . $data->nid : "";
        print "\n\t" . $node->nid . "|" . $node->type . "|" . $node->title;
        /* 
        	$node->revision = 0; 
        
        	$side = $node->field_sidebar_body['und'][0]['value']; 
        	$sside = str_replace(array("\n", "\r"), '', strip_tags($side));
        	$sbody = str_replace(array("\n", "\r"), '', strip_tags($node->body['und'][0]['value']));
        	if(stripos($side, '<iframe') !== false || stripos($side, '<form') !== false) {
        		$node->revision = 1; 
        		$node->field_sidebar_body['und'][0]['value'] = '';		
        	}
        
        	if(empty($sside) && empty($sbody)) {
        		$node->revision = 1; 
        		$node->published = 0; 
        		$node->comment = "Empty content? Unpublishing....";
        	}
コード例 #28
0
 /**
  * Deletes a content item
  *
  * @param int $nid ["path","0"]
  *  The nid of the content item to delete
  * @return bool
  *
  * @Access(callback='ConglomerateContentResource::access', args={'delete'}, appendArgs=true)
  */
 public static function delete($nid)
 {
     node_delete($nid);
     return TRUE;
 }
コード例 #29
0
ファイル: ajaxserver.php プロジェクト: dalia-m-elsayed/spica
function filedepot_dispatcher($action)
{
    global $user;
    $filedepot = filedepot_filedepot();
    $nexcloud = filedepot_nexcloud();
    module_load_include('php', 'filedepot', 'lib-theme');
    module_load_include('php', 'filedepot', 'lib-ajaxserver');
    module_load_include('php', 'filedepot', 'lib-common');
    if (function_exists('timer_start')) {
        timer_start('filedepot_timer');
    }
    firelogmsg("AJAX Server code executing - action: {$action}");
    switch ($action) {
        case 'archive':
            if (isset($_GET['checked_files']) && isset($_GET['checked_folders'])) {
                module_load_include('php', 'filedepot', 'filedepot_archiver.class');
                $checked_files = json_decode($_GET['checked_files'], TRUE);
                $checked_folders = json_decode($_GET['checked_folders'], TRUE);
                //print_r($checked_files);
                //die(1);
                $fa = new filedepot_archiver();
                $fa->createAndCleanArchiveDirectory();
                $fa->addCheckedObjectArrays($checked_files, $checked_folders);
                $fa->createArchive();
                $fa->close();
                $fa->download();
                return;
            } else {
                echo "Invalid Parameters";
                return;
            }
            break;
        case 'getfilelisting':
            $cid = intval($_POST['cid']);
            if ($cid > 0) {
                if (db_query("SELECT count(*) FROM {filedepot_categories} WHERE cid=:cid", array(':cid' => $cid))->fetchField() == 1) {
                    $filedepot->ajaxBackgroundMode = TRUE;
                }
            }
            $reportmode = check_plain($_POST['reportmode']);
            $filedepot->activeview = $reportmode;
            $filedepot->cid = $cid;
            ctools_include('object-cache');
            $cache = ctools_object_cache_set('filedepot', 'folder', $cid);
            $data = filedepotAjaxServer_getfilelisting();
            break;
        case 'getfolderlisting':
            $filedepot->ajaxBackgroundMode = TRUE;
            $cid = intval($_POST['cid']);
            $reportmode = check_plain($_POST['reportmode']);
            if ($cid > 0) {
                ctools_include('object-cache');
                $cache = ctools_object_cache_set('filedepot', 'folder', $cid);
                $filedepot->cid = $cid;
                $filedepot->activeview = $reportmode;
                $data = filedepotAjaxServer_getfilelisting();
                firelogmsg("Completed generating FileListing");
            } else {
                $data = array('retcode' => 500);
            }
            break;
        case 'getleftnavigation':
            $data = filedepotAjaxServer_generateLeftSideNavigation();
            break;
        case 'getmorefiledata':
            /** Need to use XML instead of JSON format for return data.
             * It's taking up to 1500ms to interpret (eval) the JSON data into an object in the client code
             * Parsing the XML is about 10ms
             */
            $cid = intval($_POST['cid']);
            $level = intval($_POST['level']);
            $foldernumber = check_plain($_POST['foldernumber']);
            $filedepot->activeview = 'getmoredata';
            $filedepot->cid = $cid;
            $filedepot->lastRenderedFolder = $cid;
            $retval = '<result>';
            $retval .= '<retcode>200</retcode>';
            $retval .= '<displayhtml>' . htmlspecialchars(nexdocsrv_generateFileListing($cid, $level, $foldernumber), ENT_QUOTES, 'utf-8') . '</displayhtml>';
            $retval .= '</result>';
            firelogmsg("Completed generating AJAX return data - cid: {$cid}");
            break;
        case 'getmorefolderdata':
            /* Need to use XML instead of JSON format for return data.
               It's taking up to 1500ms to interpret (eval) the JSON data into an object in the client code
               Parsing the XML is about 10ms
               */
            $cid = intval($_POST['cid']);
            $level = intval($_POST['level']);
            // Need to remove the last part of the passed in foldernumber as it's the incremental file number
            // Which we recalculate in template_preprocess_filelisting()
            $x = explode('.', check_plain($_POST['foldernumber']));
            $x2 = array_pop($x);
            $foldernumber = implode('.', $x);
            $filedepot->activeview = 'getmorefolderdata';
            $filedepot->cid = $cid;
            $filedepot->lastRenderedFolder = $cid;
            $retval = '<result>';
            $retval .= '<retcode>200</retcode>';
            $retval .= '<displayhtml>' . htmlspecialchars(nexdocsrv_generateFileListing($cid, $level, $foldernumber), ENT_QUOTES, 'utf-8') . '</displayhtml>';
            $retval .= '</result>';
            firelogmsg("Completed generating AJAX return data - cid: {$cid}");
            break;
        case 'rendernewfilefolderoptions':
            $cid = intval($_POST['cid']);
            $data['displayhtml'] = theme('filedepot_newfiledialog_folderoptions', array('cid' => $cid));
            break;
        case 'rendernewfolderform':
            $cid = intval($_POST['cid']);
            $data['displayhtml'] = theme('filedepot_newfolderdialog', array('cid' => $cid));
            break;
        case 'createfolder':
            $node = (object) array('uid' => $user->uid, 'name' => $user->name, 'type' => 'filedepot_folder', 'title' => $_POST['catname'], 'parentfolder' => intval($_POST['catparent']), 'folderdesc' => $_POST['catdesc'], 'inherit' => intval($_POST['catinherit']));
            if ($node->parentfolder == 0 and !user_access('administer filedepot')) {
                $data['errmsg'] = t('Error creating Folder - invalid parent folder');
                $data['retcode'] = 500;
            } else {
                node_save($node);
                if ($node->nid) {
                    $data['displaycid'] = $filedepot->cid;
                    $data['retcode'] = 200;
                } else {
                    $data['errmsg'] = t('Error creating Folder');
                    $data['retcode'] = 500;
                }
            }
            break;
        case 'deletefolder':
            $data = array();
            $cid = intval($_POST['cid']);
            $token = isset($_POST['token']) ? $_POST['token'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_FOLDERMGMT)) {
                $data['retcode'] = 403;
                // Forbidden
            } else {
                $query = db_query("SELECT cid,pid,nid FROM {filedepot_categories} WHERE cid=:cid", array(':cid' => $cid));
                $A = $query->fetchAssoc();
                if ($cid > 0 and $A['cid'] = $cid) {
                    if ($filedepot->checkPermission($cid, 'admin')) {
                        node_delete($A['nid']);
                        $filedepot->cid = $A['pid'];
                        // Set the new active directory to the parent folder
                        $data['retcode'] = 200;
                        $data['activefolder'] = theme('filedepot_activefolder');
                        $data['displayhtml'] = filedepot_displayFolderListing($filedepot->cid);
                        $data = filedepotAjaxServer_generateLeftSideNavigation($data);
                    } else {
                        $data['retcode'] = 403;
                        // Forbidden
                    }
                } else {
                    $data['retcode'] = 404;
                    // Not Found
                }
            }
            break;
        case 'updatefolder':
            $token = isset($_POST['token']) ? $_POST['token'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_FOLDERMGMT)) {
                $data['retcode'] = 403;
                // Forbidden
            } else {
                $data = filedepotAjaxServer_updateFolder();
            }
            break;
        case 'setfolderorder':
            $cid = intval($_POST['cid']);
            $filedepot->cid = intval($_POST['listingcid']);
            $token = isset($_POST['ltoken']) ? $_POST['ltoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_LISTING)) {
                $data['retcode'] = 403;
                // Forbidden
            } else {
                if ($filedepot->checkPermission($cid, 'admin')) {
                    // Check and see if any subfolders don't yet have a order value - if so correct
                    $maxorder = 0;
                    $pid = db_query("SELECT pid FROM {filedepot_categories} WHERE cid=:cid", array(':cid' => $cid))->fetchField();
                    $maxquery = db_query_range("SELECT folderorder FROM {filedepot_categories} WHERE pid=:pid ORDER BY folderorder ASC", 0, 1, array(':pid' => $pid))->fetchField();
                    $next_folderorder = $maxorder + 10;
                    $query = db_query("SELECT cid FROM {filedepot_categories} WHERE pid=:pid AND folderorder = 0", array(':pid' => $pid));
                    while ($B = $query->fetchAssoc()) {
                        db_query("UPDATE {filedepot_categories} SET folderorder=:folderorder WHERE cid=:cid", array(':folderorder' => $next_folderorder, ':cid' => $B['cid']));
                        $next_folderorder += 10;
                    }
                    $itemquery = db_query("SELECT * FROM {filedepot_categories} WHERE cid=:cid", array(':cid' => $cid));
                    $retval = 0;
                    while ($A = $itemquery->fetchAssoc()) {
                        if ($_POST['direction'] == 'down') {
                            $sql = "SELECT folderorder FROM {filedepot_categories} WHERE pid=:pid ";
                            $sql .= "AND folderorder > :folderorder ORDER BY folderorder ASC ";
                            $nextorder = db_query_range($sql, 0, 1, array(':pid' => $A['pid'], ':folderorder' => $A['folderorder']))->fetchField();
                            if ($nextorder > $A['folderorder']) {
                                $folderorder = $nextorder + 5;
                            } else {
                                $folderorder = $A['folderorder'];
                            }
                            db_query("UPDATE {filedepot_categories} SET folderorder=:folderorder WHERE cid=:cid", array(':folderorder' => $folderorder, ':cid' => $cid));
                        } elseif ($_POST['direction'] == 'up') {
                            $sql = "SELECT folderorder FROM {filedepot_categories} WHERE pid=:pid ";
                            $sql .= "AND folderorder < :folderorder ORDER BY folderorder DESC ";
                            $nextorder = db_query_range($sql, 0, 1, array(':pid' => $A['pid'], ':folderorder' => $A['folderorder']))->fetchField();
                            $folderorder = $nextorder - 5;
                            if ($folderorder <= 0) {
                                $folderorder = 0;
                            }
                            db_query("UPDATE {filedepot_categories} SET folderorder=:folderorder WHERE cid=:cid", array(':folderorder' => $folderorder, ':cid' => $cid));
                        }
                    }
                    /* Re-order any folders that may have just been moved */
                    $query = db_query("SELECT cid,folderorder from {filedepot_categories} WHERE pid=:pid ORDER BY folderorder", array(':pid' => $pid));
                    $folderorder = 10;
                    $stepnumber = 10;
                    while ($A = $query->fetchAssoc()) {
                        if ($folderorder != $A['folderOrder']) {
                            db_query("UPDATE {filedepot_categories} SET folderorder=:folderorder WHERE cid=:cid", array(':folderorder' => $folderorder, ':cid' => $A['cid']));
                        }
                        $folderorder += $stepnumber;
                    }
                    $data['retcode'] = 200;
                    $data['displayhtml'] = filedepot_displayFolderListing($filedepot->cid);
                } else {
                    $data['retcode'] = 400;
                }
            }
            break;
        case 'updatefoldersettings':
            $cid = intval($_POST['cid']);
            $notifyadd = intval($_POST['fileadded_notify']);
            $notifychange = intval($_POST['filechanged_notify']);
            if ($user->uid > 0 and $cid >= 1) {
                // Update the personal folder notifications for user
                if (db_query("SELECT count(*) FROM {filedepot_notifications} WHERE cid=:cid AND uid=:uid", array(':cid' => $cid, ':uid' => $user->uid))->fetchField() == 0) {
                    $sql = "INSERT INTO {filedepot_notifications} (cid,cid_newfiles,cid_changes,uid,date) ";
                    $sql .= "VALUES (:cid,:notifyadd,:notifychange,:uid,:time)";
                    db_query($sql, array(':cid' => $cid, ':notifyadd' => $notifyadd, ':notifychange' => $notifychange, ':uid' => $user->uid, ':time' => time()));
                } else {
                    $sql = "UPDATE {filedepot_notifications} set cid_newfiles=:notifyadd, ";
                    $sql .= "cid_changes=:notifychange, date=:time ";
                    $sql .= "WHERE uid=:uid and cid=:cid";
                    db_query($sql, array(':notifyadd' => $notifyadd, ':notifychange' => $notifychange, ':time' => time(), ':uid' => $user->uid, ':cid' => $cid));
                }
                $data['retcode'] = 200;
                $data['displayhtml'] = filedepot_displayFolderListing($filedepot->cid);
            } else {
                $data['retcode'] = 500;
            }
            break;
        case 'loadfiledetails':
            $data = filedepotAjaxServer_loadFileDetails();
            break;
        case 'refreshfiledetails':
            $reportmode = check_plain($_POST['reportmode']);
            $fid = intval($_POST['id']);
            $cid = db_query("SELECT cid FROM {filedepot_files} WHERE fid=:fid", array(':fid' => $fid))->fetchField();
            if ($filedepot->checkPermission($cid, 'view')) {
                $data['retcode'] = 200;
                $data['fid'] = $fid;
                $data['displayhtml'] = theme('filedepot_filedetail', array('fid' => $fid, 'reportmode' => $reportmode));
            } else {
                $data['retcode'] = 400;
                $data['error'] = t('Invalid access');
            }
            break;
        case 'updatenote':
            $fid = intval($_POST['fid']);
            $version = intval($_POST['version']);
            $note = check_plain($_POST['note']);
            $reportmode = check_plain($_POST['reportmode']);
            $token = isset($_POST['ftoken']) ? $_POST['ftoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_FILEDETAILS)) {
                $data['retcode'] = 403;
                // forbidden
            } elseif ($fid > 0) {
                db_query("UPDATE {filedepot_fileversions} SET notes=:notes WHERE fid=:fid and version=:version", array(':notes' => $note, ':fid' => $fid, ':version' => $version));
                $data['retcode'] = 200;
                $data['fid'] = $fid;
                $data['displayhtml'] = theme('filedepot_filedetail', array('fid' => $fid, 'reportmode' => $reportmode));
            } else {
                $data['retcode'] = 400;
            }
            break;
        case 'getfolderperms':
            $cid = intval($_POST['cid']);
            if ($cid > 0) {
                if ($filedepot->ogenabled) {
                    $data['html'] = theme('filedepot_folderperms_ogenabled', array('cid' => $cid, 'token' => drupal_get_token(FILEDEPOT_TOKEN_FOLDERPERMS)));
                } else {
                    $data['html'] = theme('filedepot_folderperms', array('cid' => $cid, 'token' => drupal_get_token(FILEDEPOT_TOKEN_FOLDERPERMS)));
                }
                $data['retcode'] = 200;
            } else {
                $data['retcode'] = 404;
            }
            break;
        case 'delfolderperms':
            $id = intval($_POST['id']);
            $token = isset($_POST['token']) ? $_POST['token'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_FOLDERPERMS)) {
                $data['retcode'] = 403;
                // forbidden
            } elseif ($id > 0) {
                $query = db_query("SELECT catid, permtype, permid FROM  {filedepot_access} WHERE accid=:accid", array(':accid' => $id));
                $A = $query->fetchAssoc();
                if ($filedepot->checkPermission($A['catid'], 'admin')) {
                    db_delete('filedepot_access')->condition('accid', $id)->execute();
                    db_update('filedepot_usersettings')->fields(array('allowable_view_folders' => ''))->execute();
                    // For this folder - I need to update the access metrics now that a permission has been removed
                    $nexcloud->update_accessmetrics($A['catid']);
                    if ($filedepot->ogenabled) {
                        $data['html'] = theme('filedepot_folderperms_ogenabled', array('cid' => $A['catid'], 'token' => drupal_get_token(FILEDEPOT_TOKEN_FOLDERPERMS)));
                    } else {
                        $data['html'] = theme('filedepot_folderperms', array('cid' => $A['catid'], 'token' => drupal_get_token(FILEDEPOT_TOKEN_FOLDERPERMS)));
                    }
                    $data['retcode'] = 200;
                } else {
                    $data['retcode'] = 403;
                    // Forbidden
                }
            } else {
                $data['retcode'] = 404;
                // Not Found
            }
            break;
        case 'addfolderperm':
            $cid = intval($_POST['catid']);
            $token = isset($_POST['token']) ? $_POST['token'] : NULL;
            if (!isset($_POST['cb_access'])) {
                $data['retcode'] = 204;
                // No permission options selected - return 'No content' statuscode
            } elseif ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_FOLDERPERMS)) {
                $data['retcode'] = 403;
                // forbidden
            } elseif ($filedepot->updatePerms($cid, $_POST['cb_access'], $_POST['selusers'], $_POST['selgroups'], $_POST['selroles'])) {
                if (is_array($_POST['selroles']) and count($_POST['selroles']) > 0) {
                    foreach ($_POST['selroles'] as $roleid) {
                        $roleid = intval($roleid);
                        if ($roleid > 0) {
                            $nexcloud->update_accessmetrics($cid);
                        }
                    }
                }
                if ($filedepot->ogenabled) {
                    if (is_array($_POST['selgroups']) and count($_POST['selgroups']) > 0) {
                        foreach ($_POST['selgroups'] as $groupid) {
                            $groupid = intval($groupid);
                            if ($groupid > 0) {
                                $nexcloud->update_accessmetrics($cid);
                            }
                        }
                    }
                    $data['html'] = theme('filedepot_folderperms_ogenabled', array('cid' => $cid, 'token' => drupal_get_token(FILEDEPOT_TOKEN_FOLDERPERMS)));
                } else {
                    $data['html'] = theme('filedepot_folderperms', array('cid' => $cid, 'token' => drupal_get_token(FILEDEPOT_TOKEN_FOLDERPERMS)));
                }
                $data['retcode'] = 200;
            } else {
                $data['retcode'] = 403;
                // Forbidden
            }
            break;
        case 'updatefile':
            $fid = intval($_POST['id']);
            $folder_id = intval($_POST['folder']);
            $version = intval($_POST['version']);
            $filetitle = $_POST['filetitle'];
            $description = $_POST['description'];
            $vernote = $_POST['version_note'];
            $approved = check_plain($_POST['approved']);
            $tags = $_POST['tags'];
            $data = array();
            $data['tagerror'] = '';
            $data['errmsg'] = '';
            $token = isset($_POST['ftoken']) ? $_POST['ftoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_FILEDETAILS)) {
                $data['retcode'] = 403;
                // forbidden
                $data['errmsg'] = t('Invalid request');
            } elseif ($_POST['cid'] == 'incoming' and $fid > 0) {
                $filemoved = FALSE;
                $sql = "UPDATE {filedepot_import_queue} SET orig_filename=:filename, description=:description,";
                $sql .= "version_note=:notes WHERE id=:fid";
                db_query($sql, array(':filename' => $filetitle, ':description' => $description, ':notes' => $vernote, ':fid' => $fid));
                $data['retcode'] = 200;
                if ($folder_id > 0 and $filedepot->moveIncomingFile($fid, $folder_id)) {
                    $filemoved = TRUE;
                    $filedepot->activeview = 'incoming';
                    $data = filedepotAjaxServer_generateLeftSideNavigation($data);
                    $data['displayhtml'] = filedepot_displayFolderListing();
                }
            } elseif ($fid > 0) {
                $filemoved = FALSE;
                if ($approved == 0) {
                    $sql = "UPDATE {filedepot_filesubmissions} SET title=:title, description=:description,";
                    $sql .= "version_note=:notes, cid=:cid, tags=:tags WHERE id=:fid;";
                    db_query($sql, array(':title' => $filetitle, ':description' => $description, ':notes' => $vernote, ':cid' => $folder_id, ':tags' => $tags, ':fid' => $fid));
                    $data['cid'] = $folder_id;
                    $data['tags'] = '';
                } else {
                    $query = db_query("SELECT fname,cid,version,submitter FROM {filedepot_files} WHERE fid=:fid", array(':fid' => $fid));
                    list($fname, $cid, $current_version, $submitter) = array_values($query->fetchAssoc());
                    // Allow updating the category, title, description and image for the current version and primary file record
                    if ($version == $current_version) {
                        db_query("UPDATE {filedepot_files} SET title=:title,description=:desc,date=:time WHERE fid=:fid", array(':title' => $filetitle, ':desc' => $description, ':time' => time(), ':fid' => $fid));
                        // Test if user has selected a different directory and if they have perms then move else return FALSE;
                        if ($folder_id > 0) {
                            $newcid = $folder_id;
                            if ($cid != $newcid) {
                                $filemoved = $filedepot->moveFile($fid, $newcid);
                                if ($filemoved == FALSE) {
                                    $data['errmsg'] = t('Error moving file');
                                }
                            }
                            $data['cid'] = $newcid;
                        } else {
                            $data['cid'] = $cid;
                        }
                        unset($_POST['tags']);
                        // Format tags will check this to format tags in case we are doing a search which we are not in this case.
                        $data['tags'] = filedepot_formatfiletags($tags);
                    }
                    db_query("UPDATE {filedepot_fileversions} SET notes=:notes WHERE fid=:fid and version=:version", array(':notes' => $vernote, ':fid' => $fid, ':version' => $version));
                    // Update the file tags if role or group permission set -- we don't support tag access perms at the user level.
                    if ($filedepot->checkPermission($folder_id, 'view', 0, FALSE)) {
                        if ($filedepot->checkPermission($folder_id, 'admin', 0, FALSE) or $user->uid == $submitter) {
                            $admin = TRUE;
                        } else {
                            $admin = FALSE;
                        }
                        if (!$nexcloud->update_tags($fid, $tags, $admin)) {
                            $data['tagerror'] = t('Tags not added - Group or Role assigned view perms required');
                            $data['tags'] = '';
                        }
                    } else {
                        $data['tagerror'] = t('Problem adding or updating tags');
                        $data['tags'] = '';
                    }
                }
                $data['retcode'] = 200;
                $data['tagcloud'] = theme('filedepot_tagcloud');
            } else {
                $data['retcode'] = 500;
                $data['errmsg'] = t('Invalid File');
            }
            $data['description'] = nl2br(filter_xss($description));
            $data['fid'] = $fid;
            $data['filename'] = filter_xss($filetitle);
            $data['filemoved'] = $filemoved;
            break;
        case 'deletefile':
            $fid = intval($_POST['fid']);
            $token = isset($_POST['ftoken']) ? $_POST['ftoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_FILEDETAILS)) {
                $data['retcode'] = 403;
                // forbidden
            } elseif ($user->uid > 0 and $fid > 0) {
                $data = filedepotAjaxServer_deleteFile($fid);
            } else {
                $data['retcode'] = 500;
            }
            break;
        case 'deletecheckedfiles':
            $token = isset($_POST['ltoken']) ? $_POST['ltoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_LISTING)) {
                $data['retcode'] = 403;
                // forbidden
            } elseif ($user->uid > 0) {
                $data = filedepotAjaxServer_deleteCheckedFiles();
            } else {
                $data['retcode'] = 500;
            }
            break;
        case 'deleteversion':
            $fid = intval($_POST['fid']);
            $version = intval($_POST['version']);
            $reportmode = check_plain($_POST['reportmode']);
            $token = isset($_POST['ftoken']) ? $_POST['ftoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_FILEDETAILS)) {
                $data['retcode'] = 403;
                // forbidden
            } elseif ($fid > 0 and $version > 0) {
                if ($filedepot->deleteVersion($fid, $version)) {
                    $data['retcode'] = 200;
                    $data['fid'] = $fid;
                    $data['displayhtml'] = theme('filedepot_filedetail', array('fid' => $fid, 'reportmode' => $reportmode));
                } else {
                    $data['retcode'] = 400;
                }
            } else {
                $data['retcode'] = 400;
            }
            break;
        case 'togglefavorite':
            $id = intval($_POST['id']);
            $token = isset($_POST['ltoken']) ? $_POST['ltoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_LISTING)) {
                $data['retcode'] = 403;
                // forbidden
            } elseif ($user->uid > 0 and $id >= 1) {
                if (db_query("SELECT count(fid) FROM {filedepot_favorites} WHERE uid=:uid AND fid=:fid", array(':uid' => $user->uid, ':fid' => $id))->fetchField() > 0) {
                    $data['favimgsrc'] = base_path() . drupal_get_path('module', 'filedepot') . '/css/images/' . $filedepot->getFileIcon('favorite-off');
                    db_query("DELETE FROM {filedepot_favorites} WHERE uid=:uid AND fid=:fid", array(':uid' => $user->uid, ':fid' => $id));
                } else {
                    $data['favimgsrc'] = base_path() . drupal_get_path('module', 'filedepot') . '/css/images/' . $filedepot->getFileIcon('favorite-on');
                    db_query("INSERT INTO {filedepot_favorites} (uid,fid) VALUES (:uid,:fid)", array(':uid' => $user->uid, ':fid' => $id));
                }
                $data['retcode'] = 200;
            } else {
                $data['retcode'] = 400;
            }
            break;
        case 'markfavorite':
            $token = isset($_POST['ltoken']) ? $_POST['ltoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_LISTING)) {
                $data['retcode'] = 403;
                // forbidden
            } elseif ($user->uid > 0) {
                $cid = intval($_POST['cid']);
                $reportmode = check_plain($_POST['reportmode']);
                $fileitems = check_plain($_POST['checkeditems']);
                $files = explode(',', $fileitems);
                $filedepot->cid = $cid;
                $filedepot->activeview = $reportmode;
                foreach ($files as $id) {
                    if ($id > 0 and db_query("SELECT COUNT(*) FROM {filedepot_favorites} WHERE uid=:uid AND fid=:fid", array(':uid' => $user->uid, ':fid' => $id))->fetchField() == 0) {
                        db_query("INSERT INTO {filedepot_favorites} (uid,fid) VALUES (:uid,:fid)", array(':uid' => $user->uid, 'fid' => $id));
                    }
                }
                $data['retcode'] = 200;
                $data['displayhtml'] = filedepot_displayFolderListing($cid);
            }
            break;
        case 'clearfavorite':
            $token = isset($_POST['ltoken']) ? $_POST['ltoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_LISTING)) {
                $data['retcode'] = 403;
                // forbidden
            } elseif ($user->uid > 0) {
                $cid = intval($_POST['cid']);
                $reportmode = check_plain($_POST['reportmode']);
                $fileitems = check_plain($_POST['checkeditems']);
                $files = explode(',', $fileitems);
                $filedepot->cid = $cid;
                $filedepot->activeview = $reportmode;
                foreach ($files as $id) {
                    if ($id > 0 and db_query("SELECT COUNT(*) FROM {filedepot_favorites} WHERE uid=:uid AND fid=:fid", array(':uid' => $user->uid, ':fid' => $id))->fetchField() == 1) {
                        db_query("DELETE FROM {filedepot_favorites} WHERE uid=:uid AND fid=:fid", array(':uid' => $user->uid, ':fid' => $id));
                    }
                }
                $data['retcode'] = 200;
                $data['displayhtml'] = filedepot_displayFolderListing($cid);
            }
            break;
        case 'togglelock':
            $fid = intval($_POST['fid']);
            $token = isset($_POST['ftoken']) ? $_POST['ftoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_FILEDETAILS)) {
                $data['error'] = t('Error locking file');
            } else {
                $data['error'] = '';
                $data['fid'] = $fid;
                $query = db_query("SELECT status FROM {filedepot_files} WHERE fid=:fid", array(':fid' => $fid));
                if ($query) {
                    list($status) = array_values($query->fetchAssoc());
                    if ($status == 1) {
                        db_query("UPDATE {filedepot_files} SET status='2', status_changedby_uid=:uid WHERE fid=:fid", array(':uid' => $user->uid, ':fid' => $fid));
                        $stat_user = db_query("SELECT name FROM {users} WHERE uid=:uid", array(':uid' => $user->uid))->fetchField();
                        $data['message'] = 'File Locked successfully';
                        $data['locked_message'] = '* ' . t('Locked by %name', array('%name' => $stat_user));
                        $data['locked'] = TRUE;
                    } else {
                        db_query("UPDATE {filedepot_files} SET status='1', status_changedby_uid=:uid WHERE fid=:fid", array(':uid' => $user->uid, ':fid' => $fid));
                        $data['message'] = 'File Un-Locked successfully';
                        $data['locked'] = FALSE;
                    }
                } else {
                    $data['error'] = t('Error locking file');
                }
            }
            break;
        case 'movecheckedfiles':
            $token = isset($_POST['ltoken']) ? $_POST['ltoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_LISTING)) {
                $data['retcode'] = 403;
                // forbidden
            } elseif ($user->uid > 0) {
                $data = filedepotAjaxServer_moveCheckedFiles();
            } else {
                $data['retcode'] = 500;
            }
            break;
        case 'rendermoveform':
            $data['displayhtml'] = theme('filedepot_movefiles_form');
            break;
        case 'rendermoveincoming':
            $data['displayhtml'] = theme('filedepot_moveincoming_form');
            break;
        case 'togglesubscribe':
            $fid = intval($_POST['fid']);
            $cid = intval($_POST['cid']);
            $token = isset($_POST['ftoken']) ? $_POST['ftoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_FILEDETAILS)) {
                $data['error'] = t('Error subscribing');
            } else {
                global $base_url;
                $data['error'] = '';
                $data['fid'] = $fid;
                $ret = filedepotAjaxServer_updateFileSubscription($fid, 'toggle');
                // @TODO: Notifyicon does not appear to be implemented
                if ($ret['retcode'] === TRUE) {
                    $data['retcode'] = 200;
                    if ($ret['subscribed'] === TRUE) {
                        $data['subscribed'] = TRUE;
                        $data['message'] = 'You will be notified of any new versions of this file';
                        $path = drupal_get_path('module', 'filedepot') . '/css/images/email-green.gif';
                        $data['notifyicon'] = $base_url . '/' . $path;
                        $data['notifymsg'] = 'Notification Enabled - Click to change';
                    } elseif ($ret['subscribed'] === FALSE) {
                        $data['subscribed'] = FALSE;
                        $data['message'] = 'You will not be notified of any new versions of this file';
                        $path = drupal_get_path('module', 'filedepot') . '/css/images/email-regular.gif';
                        $data['notifyicon'] = $base_url . '/' . $path;
                        $data['notifymsg'] = 'Notification Disabled - Click to change';
                    }
                } else {
                    $data['error'] = t('Error accessing file record');
                    $data['retcode'] = 404;
                }
            }
            break;
        case 'updatenotificationsettings':
            if ($user->uid > 0) {
                if (db_query("SELECT count(uid) FROM {filedepot_usersettings} WHERE uid=:uid", array(':uid' => $user->uid))->fetchField() == 0) {
                    db_query("INSERT INTO {filedepot_usersettings} (uid) VALUES ( :uid )", array(':uid' => $user->uid));
                }
                $sql = "UPDATE {filedepot_usersettings} SET notify_newfile=:newfile,notify_changedfile=:changefile,allow_broadcasts=:broadcast WHERE uid=:uid";
                db_query($sql, array(':newfile' => $_POST['fileadded_notify'], ':changefile' => $_POST['fileupdated_notify'], ':broadcast' => $_POST['admin_broadcasts'], ':uid' => $user->uid));
                $data['retcode'] = 200;
                $data['displayhtml'] = theme('filedepot_notifications');
            } else {
                $data['retcode'] = 500;
            }
            break;
        case 'deletenotification':
            $id = intval($_POST['id']);
            if ($user->uid > 0 and $id > 0) {
                db_query("DELETE FROM {filedepot_notifications} WHERE id=:id AND uid=:uid", array(':id' => $id, ':uid' => $user->uid));
                $data['retcode'] = 200;
                $data['displayhtml'] = theme('filedepot_notifications');
            } else {
                $data['retcode'] = 500;
            }
            break;
        case 'clearnotificationlog':
            db_query("DELETE FROM {filedepot_notificationlog} WHERE target_uid=:uid", array(':uid' => $user->uid));
            $data['retcode'] = 200;
            break;
        case 'multisubscribe':
            $token = isset($_POST['ltoken']) ? $_POST['ltoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_LISTING)) {
                $data['retcode'] = 403;
                // forbidden
            } elseif ($user->uid > 0) {
                $reportmode = check_plain($_POST['reportmode']);
                $fileitems = check_plain($_POST['checkeditems']);
                $folderitems = check_plain($_POST['checkedfolders']);
                $filedepot->cid = intval($_POST['cid']);
                $filedepot->activeview = check_plain($_POST['reportmode']);
                if (!empty($fileitems)) {
                    $files = explode(',', $fileitems);
                    foreach ($files as $fid) {
                        filedepotAjaxServer_updateFileSubscription($fid, 'add');
                    }
                }
                if (!empty($folderitems)) {
                    $folders = explode(',', $folderitems);
                    foreach ($folders as $cid) {
                        if (db_query("SELECT count(id) FROM {filedepot_notifications} WHERE cid=:cid AND uid=:uid", array(':cid' => $cid, ':uid' => $user->uid))->fetchField() == 0) {
                            $sql = "INSERT INTO {filedepot_notifications} (cid,cid_newfiles,cid_changes,uid,date) ";
                            $sql .= "VALUES (:cid,1,1,:uid,:time)";
                            db_query($sql, array(':cid' => $cid, ':uid' => $user->uid, ':time' => time()));
                        }
                    }
                }
                $data['retcode'] = 200;
                $data = filedepotAjaxServer_generateLeftSideNavigation($data);
                $data['displayhtml'] = filedepot_displayFolderListing($filedepot->cid);
            } else {
                $data['retcode'] = 500;
            }
            break;
        case 'autocompletetag':
            $matches = $nexcloud->get_matchingtags($_GET['query']);
            $retval = implode("\n", $matches);
            break;
        case 'refreshtagcloud':
            $data['retcode'] = 200;
            $data['tagcloud'] = theme('filedepot_tagcloud');
            break;
        case 'search':
            $query = $_POST['query'];
            if (!empty($query)) {
                $filedepot->activeview = 'search';
                $filedepot->cid = 0;
                $data['retcode'] = 200;
                $data['displayhtml'] = filedepot_displaySearchListing($query);
                $data['header'] = theme('filedepot_header');
                $data['activefolder'] = theme('filedepot_activefolder');
            } else {
                $data['retcode'] = 400;
            }
            break;
        case 'searchtags':
            if (isset($_POST['tags'])) {
                $tags = stripslashes($_POST['tags']);
            } else {
                $tags = '';
            }
            if (isset($_POST['removetag'])) {
                $removetag = stripslashes($_POST['removetag']);
            } else {
                $removetag = '';
            }
            $current_search_tags = '';
            $filedepot->activeview = 'searchtags';
            $filedepot->cid = 0;
            if (!empty($tags)) {
                if (!empty($removetag)) {
                    $removetag = stripslashes($removetag);
                    $atags = explode(',', $tags);
                    $key = array_search($removetag, $atags);
                    if ($key !== FALSE) {
                        unset($atags[$key]);
                    }
                    $tags = implode(',', $atags);
                    $_POST['tags'] = $tags;
                } else {
                    $removetag = '';
                }
                if (!empty($tags)) {
                    $data['searchtags'] = stripslashes($tags);
                    $atags = explode(',', $tags);
                    if (count($atags) >= 1) {
                        foreach ($atags as $tag) {
                            $tag = trim($tag);
                            // added to handle extra space thats added when removing a tag - thats between 2 other tags
                            if (!empty($tag)) {
                                $current_search_tags .= theme('filedepot_searchtag', array('searchtag' => addslashes($tag), 'label' => check_plain($tag)));
                            }
                        }
                    }
                    $data['retcode'] = 200;
                    $data['currentsearchtags'] = $current_search_tags;
                    $data['displayhtml'] = filedepot_displayTagSearchListing($tags);
                    $data['tagcloud'] = theme('filedepot_tagcloud');
                    $data['header'] = theme('filedepot_header');
                    $data['activefolder'] = theme('filedepot_activefolder');
                } else {
                    unset($_POST['tags']);
                    $filedepot->activeview = 'latestfiles';
                    $data['retcode'] = 200;
                    $data['currentsearchtags'] = '';
                    $data['tagcloud'] = theme('filedepot_tagcloud');
                    $data['displayhtml'] = filedepot_displayFolderListing($filedepot->cid);
                    $data['header'] = theme('filedepot_header');
                    $data['activefolder'] = theme('filedepot_activefolder');
                }
            } else {
                $data['tagcloud'] = theme('filedepot_tagcloud');
                $data['retcode'] = 203;
                // Partial Information
            }
            break;
        case 'approvefile':
            $id = intval($_POST['id']);
            $token = isset($_POST['ltoken']) ? $_POST['ltoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_LISTING)) {
                $data['retcode'] = 403;
                // forbidden
            } elseif ($user->uid > 0 and $filedepot->approveFileSubmission($id)) {
                $filedepot->cid = 0;
                $filedepot->activeview = 'approvals';
                $data = filedepotAjaxServer_getfilelisting();
                $data = filedepotAjaxServer_generateLeftSideNavigation($data);
                $data['retcode'] = 200;
            } else {
                $data['retcode'] = 400;
            }
            break;
        case 'approvesubmissions':
            $token = isset($_POST['ltoken']) ? $_POST['ltoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_LISTING)) {
                $data['retcode'] = 403;
                // forbidden
            } elseif ($user->uid > 0) {
                $reportmode = check_plain($_POST['reportmode']);
                $fileitems = check_plain($_POST['checkeditems']);
                $files = explode(',', $fileitems);
                $approved_files = 0;
                $filedepot->activeview = 'approvals';
                foreach ($files as $id) {
                    // Check if this is a valid submission record
                    if ($id > 0 and db_query("SELECT COUNT(*) FROM {filedepot_filesubmissions} WHERE id=:id", array(':id' => $id))->fetchField() == 1) {
                        // Verify that user has Admin Access to approve this file
                        $cid = db_query("SELECT cid FROM {filedepot_filesubmissions} WHERE id=:id", array(':id' => $id))->fetchField();
                        if ($cid > 0 and $filedepot->checkPermission($cid, array('admin', 'approval'), 0, FALSE)) {
                            if ($filedepot->approveFileSubmission($id)) {
                                $approved_files++;
                            }
                        }
                    }
                }
                if ($approved_files > 0) {
                    $data['retcode'] = 200;
                    $data = filedepotAjaxServer_generateLeftSideNavigation($data);
                    $data['displayhtml'] = filedepot_displayFolderListing();
                } else {
                    $data['retcode'] = 400;
                }
            }
            break;
        case 'deletesubmissions':
            $token = isset($_POST['ltoken']) ? $_POST['ltoken'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_LISTING)) {
                $data['retcode'] = 403;
                // forbidden
            } elseif ($user->uid > 0) {
                $reportmode = check_plain($_POST['reportmode']);
                $fileitems = check_plain($_POST['checkeditems']);
                $files = explode(',', $fileitems);
                $deleted_files = 0;
                $filedepot->activeview = 'approvals';
                foreach ($files as $id) {
                    // Check if this is a valid submission record
                    if ($id > 0 and db_query("SELECT COUNT(*) FROM {filedepot_filesubmissions} WHERE id=:id", array(':id' => $id))->fetchField() == 1) {
                        // Verify that user has Admin Access to approve this file
                        $cid = db_query("SELECT cid FROM {filedepot_filesubmissions} WHERE id=:id", array(':id' => $id))->fetchField();
                        if ($cid > 0 and $filedepot->checkPermission($cid, array('admin', 'approval'), 0, FALSE)) {
                            if ($filedepot->deleteSubmission($id)) {
                                $deleted_files++;
                            }
                        }
                    }
                }
                if ($deleted_files > 0) {
                    $data['retcode'] = 200;
                    $data = filedepotAjaxServer_generateLeftSideNavigation($data);
                    $data['displayhtml'] = filedepot_displayFolderListing();
                } else {
                    $data['retcode'] = 400;
                }
            }
            break;
        case 'deleteincomingfile':
            $id = intval($_POST['id']);
            $message = '';
            $token = isset($_POST['token']) ? $_POST['token'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_FOLDERMGMT)) {
                $data['retcode'] = 403;
                // forbidden
            } else {
                $fid = db_query("SELECT drupal_fid FROM {filedepot_import_queue} WHERE id=:id", array(':id' => $id))->fetchField();
                if ($fid > 0) {
                    $filepath = db_query("SELECT filepath FROM {files} WHERE fid=:fid", array(':fid' => $fid))->fetchField();
                    if (!empty($filepath) and file_exists($filepath)) {
                        @unlink($filepath);
                    }
                    db_query("DELETE FROM {files} WHERE fid=:fid", array(':fid' => $fid));
                    db_query("DELETE FROM {filedepot_import_queue} WHERE id=:id", array(':id' => $id));
                    $data['retcode'] = 200;
                    $filedepot->activeview = 'incoming';
                    $data = filedepotAjaxServer_generateLeftSideNavigation($data);
                    $data['displayhtml'] = filedepot_displayFolderListing();
                } else {
                    $data['retcode'] = 500;
                }
                $retval = json_encode($data);
            }
            break;
        case 'moveincomingfile':
            //FILEDEPOT_TOKEN_FOLDERMGMT
            $newcid = intval($_POST['newcid']);
            $id = intval($_POST['id']);
            $filedepot->activeview = 'incoming';
            $data = array();
            $token = isset($_POST['token']) ? $_POST['token'] : NULL;
            if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_FOLDERMGMT)) {
                $data['retcode'] = 403;
                // forbidden
            } elseif ($newcid > 0 and $id > 0 and $filedepot->moveIncomingFile($id, $newcid)) {
                // Send out email notifications of new file added to all users subscribed  -  Get fileid for the new file record
                $fid = db_query("SELECT fid FROM {filedepot_files} WHERE cid=:cid AND submitter=:uid ORDER BY fid DESC", array(':cid' => $newcid, ':uid' => $user->uid), 0, 1)->fetchField();
                filedepot_sendNotification($fid, FILEDEPOT_NOTIFY_NEWFILE);
                $data['retcode'] = 200;
                $data = filedepotAjaxServer_generateLeftSideNavigation($data);
                $data['displayhtml'] = filedepot_displayFolderListing();
            } else {
                $data['retcode'] = 500;
            }
            break;
        case 'broadcastalert':
            $data = array();
            if (variable_get('filedepot_default_allow_broadcasts', 1) == 0) {
                $data['retcode'] = 204;
            } else {
                $fid = intval($_POST['fid']);
                $message = check_plain($_POST['message']);
                $token = isset($_POST['ftoken']) ? $_POST['ftoken'] : NULL;
                if ($token == NULL || !drupal_valid_token($token, FILEDEPOT_TOKEN_FILEDETAILS)) {
                    $data['retcode'] = 403;
                } elseif (!empty($message) and $fid > 0) {
                    $data = filedepotAjaxServer_broadcastAlert($fid, $message);
                } else {
                    $data['retcode'] = 500;
                }
            }
            break;
    }
    ob_clean();
    if ($action != 'autocompletetag') {
        if ($action != 'getmorefiledata' and $action != 'getmorefolderdata') {
            $retval = json_encode($data);
        }
        header('Cache-Control: no-store, no-cache, must-revalidate');
        header('content-type: application/xml', TRUE);
        echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
    }
    echo $retval;
}
コード例 #30
0
 function handleBookForm($form_values)
 {
     global $base_url;
     //		print_r($form_values);
     //		exit;
     module_load_include('php', 'Fedora_Repository', 'api/fedora_item');
     module_load_include('php', 'Fedora_Repository', 'epistemetec/plugins/FileManipulation');
     $dom = new DomDocument("1.0", "UTF-8");
     $dom->formatOutput = true;
     $pid = $form_values['pid'];
     $title = $form_values['gen_collection'];
     $rootElement = $dom->createElement("foxml:digitalObject");
     $rootElement->setAttribute('VERSION', '1.1');
     $rootElement->setAttribute('PID', "{$pid}");
     $rootElement->setAttribute('xmlns:foxml', "info:fedora/fedora-system:def/foxml#");
     $rootElement->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
     $rootElement->setAttribute('xsi:schemaLocation', "info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd");
     $dom->appendChild($rootElement);
     //create standard fedora stuff
     $this->createStandardFedoraStuff($form_values, $dom, $rootElement);
     //create relationships
     $this->createRelationShips($form_values, $dom, $rootElement);
     //create dublin core
     $myForm = array();
     $myForm['dc:title'] = $title;
     $this->createQDCStream($myForm, $dom, $rootElement);
     //create mag metadata
     //module_load_include('php', 'Fedora_Repository', 'plugins/EpistemetecImageManipulation');
     //		$image = new EpistemetecImageManipulation();
     //		$image->getMetadata($form_values);
     //		//$form_values['dru_nid'] = $base_url . '/node/' . $this->createNode($pid, $title);
     $file = new FileManipulation();
     $list = $file->manipulateZip($form_values['ingest-file-location']);
     $ccks = array();
     module_load_include('php', 'Fedora_Repository', 'epistemetec/plugins/Node');
     $node = new EpistemetecNode();
     $ccks = $node->hashCCK($form_values);
     $form_values['dru_nid'] = $base_url . '/node/' . $node->createNode($ccks, ITEM_DL);
     $this->createBookStream($form_values, $dom, $rootElement);
     //drupal_set_message($form_values['ingest-file-location']);
     if (!empty($form_values['ingest-file-location'])) {
         $this->createFedoraDataStreams($form_values, $dom, $rootElement);
     }
     $collectionPid = $form_values['collection_pid'];
     $this->createPolicy($collectionPid, &$dom, &$rootElement);
     try {
         $object = Fedora_Item::ingest_from_FOXML($dom);
         if (!empty($object->pid)) {
             drupal_set_message("Item " . l($object->pid, 'fedora/repository/' . $object->pid) . " created successfully.", "status");
             //TODO: creare qui il nuovo nodo drupal e caricare il valore del pid in un campo CCK
         }
         if (!empty($_SESSION['fedora_ingest_files'])) {
             foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) {
                 file_delete($createdFile);
             }
         }
         file_delete($form_values['ingest-file-location']);
     } catch (exception $e) {
         node_delete($nid);
         drupal_set_message(t('Error Ingesting Object! ') . $e->getMessage(), 'error');
         watchdog(t("Fedora_Repository"), t("Error Ingesting Object!") . $e->getMessage(), NULL, WATCHDOG_ERROR);
         return;
     }
     $object = new Fedora_Item($pid);
     $path = drupal_get_path('module', 'Fedora_Repository');
     $stream = file_get_contents($path . "/epistemetec/xml/BOOK_COLLECTION_VIEW.xml");
     $object->add_datastream_from_string($stream, "COLLECTION_VIEW", "Collection View");
     $temp = explode(" ", $list[0]);
     $file = $temp[sizeof($temp) - 1];
     $image = new EpistemetecImageManipulation();
     $image = imageapi_image_open($file);
     imageapi_image_scale($image, 120, 120);
     $file = $file . "_TN";
     imageapi_image_close($image, $file);
     $object->add_datastream_from_file($file, "TN", "Thumbnail");
     $stream = $this->ingestPage($list, $form_values);
     $object->add_datastream_from_string($stream, "STRU", "Struttura Libro");
 }