Example #1
0
    /* === Hook === */
    foreach (cot_getextplugins('trashcan.admin.wipeall') as $pl) {
        include $pl;
    }
    /* ===== */
    $sql = $db->query("TRUNCATE {$db_trash}");
    cot_message('adm_trashcan_prune');
    cot_redirect(cot_url('admin', 'm=other&p=trashcan', '', true));
} elseif ($a == 'restore') {
    cot_check_xg();
    /* === Hook === */
    foreach (cot_getextplugins('trashcan.admin.restore') as $pl) {
        include $pl;
    }
    /* ===== */
    cot_trash_restore($id);
    cot_message('adm_trashcan_restored');
    cot_redirect(cot_url('admin', 'm=other&p=trashcan', '', true));
}
$tr_t = new XTemplate(cot_tplfile($info ? 'trashcan.info.admin' : 'trashcan.admin', 'plug', true));
$totalitems = (int) $db->query("SELECT COUNT(*) FROM {$db_trash} WHERE tr_parentid=0")->fetchColumn();
$pagenav = cot_pagenav('admin', 'm=other&p=trashcan', $d, $totalitems, $maxperpage, 'd', '', $cfg['jquery'] && $cfg['turnajax']);
$sql_query = $info ? "AND tr_id={$id} LIMIT 1" : "ORDER by tr_id DESC LIMIT {$d}, " . $maxperpage;
$sql = $db->query("SELECT t.*, u.user_name FROM {$db_trash} AS t\n\tLEFT JOIN {$db_users} AS u ON t.tr_trashedby=u.user_id\n\tWHERE tr_parentid=0 {$sql_query}");
$ii = 0;
/* === Hook - Part1 : Set === */
$extp = cot_getextplugins('trashcan.admin.loop');
/* ===== */
foreach ($sql->fetchAll() as $row) {
    $ii++;
    switch ($row['tr_type']) {
Example #2
0
/**
 * Restores a trash item
 *
 * @param int $id Trash item ID
 * @return bool Operation success or failure
 */
function cot_trash_restore($id)
{
    global $db, $db_trash, $trash_types;
    /* === Hook  === */
    foreach (cot_getextplugins('trash.restore.first') as $pl) {
        include $pl;
    }
    /* ===== */
    $id = (int) $id;
    $tsql = $db->query("SELECT * FROM {$db_trash} WHERE tr_id={$id} LIMIT 1");
    if ($res = $tsql->fetch()) {
        $data = unserialize($res['tr_datas']);
        $type = $res['tr_type'];
        $restore = true;
        $databasename = isset($trash_types[$type]) ? $trash_types[$type] : $type;
        if (isset($trash_types[$type]) && function_exists('cot_trash_' . $type . '_check')) {
            $check = 'cot_trash_' . $type . '_check';
            $restore = $check($data);
        }
        $rsql = $db->query("SELECT * FROM {$databasename} WHERE 1 LIMIT 1");
        if ($rrow = $rsql->fetch()) {
            $arraydiff = array_diff_key($data, $rrow);
            foreach ($arraydiff as $key => $val) {
                unset($data[$key]);
            }
            if (count($data) == 0 && $restore) {
                $restore = false;
            }
        }
        if ($restore) {
            $sql = $db->insert($databasename, $data);
            cot_log("{$type} #" . $res['tr_itemid'] . " restored from the trash can.", 'adm');
            if (isset($trash_types[$type]) && function_exists('cot_trash_' . $type . '_sync')) {
                $resync = 'cot_trash_' . $type . '_sync';
                $resync($data);
            }
            if ($sql > 0) {
                $db->delete($db_trash, "tr_id='" . $res['tr_id'] . "'");
                $sql2 = $db->query("SELECT tr_id FROM {$db_trash} WHERE tr_parentid='" . (int) $res['tr_id'] . "'");
                while ($row2 = $sql2->fetch()) {
                    cot_trash_restore($row2['tr_id']);
                }
                $sql2->closeCursor();
            }
        }
        /* === Hook  === */
        foreach (cot_getextplugins('trash.restore.done') as $pl) {
            include $pl;
        }
        /* ===== */
        return $sql;
    }
    return false;
}