示例#1
0
        }
        if ($cachetype == 'all' || in_array('contact', $types)) {
            writeContactCache();
        }
        if ($cachetype == 'all' || in_array('channels', $types)) {
            writeChannelsCache();
        }
        if ($cachetype == 'all' || in_array('procates', $types)) {
            writeProductsCateCache();
        }
        if ($cachetype == 'all' || in_array('links', $types)) {
            writeLinksCache();
        }
        if ($cachetype == 'all' || in_array('votes', $types)) {
            writeVotesCache();
        }
        if ($cachetype == 'all' || in_array('folders', $types)) {
            writeFoldersCache();
        }
        if ($cachetype == 'all' || in_array('users', $types)) {
            writeUsersCache();
        }
        if ($cachetype == 'all' || in_array('templatevars', $types)) {
            writeTemplatevarsCache();
        }
        succeedFlag();
        break;
    default:
        echo $_AL['all.noaction'];
        break;
}
 public function ajax()
 {
     $action = I('get.action');
     switch ($action) {
         case "createFolder":
             $folder['title'] = I('post.newfoldername');
             if (empty($folder['title'])) {
                 exit("文件夹名称为空");
             }
             $folder['updatetime'] = time();
             $folders = D('Folders');
             $folders->add($folder);
             writeFoldersCache();
             exit('ok');
             break;
         case "renameFolder":
             try {
                 $folderid = intval(I('post.folderid'));
                 $folder['title'] = I('post.newfoldername');
                 if (empty($folder['title'])) {
                     exit("error");
                 }
                 $folders = D('folders');
                 $folders->where("id={$folderid}")->setField($folder);
                 writeFoldersCache();
                 exit('ok');
             } catch (Exception $e) {
                 echo $e;
             }
             break;
         case "delFolder":
             try {
                 $folderids = I('post.ids');
                 $deltype = intval($_POST['deltype']);
                 $deltype = I('post.deltype', '', 'int');
                 if (isIntArray($folderids)) {
                     //ignore default dir
                     foreach ($folderids as $key => $folderid) {
                         if (intval($folderid) == 1) {
                             unset($folderids[$key]);
                         }
                     }
                     //del dir
                     $delfolderids = implode(",", $folderids);
                     $folders = D('Folders');
                     $folders->where("id in ({$delfolderids})")->delete();
                     $attach = D('attachments');
                     if ($deltype == 1) {
                         //del file
                         $rows = $attach->where("folderid in ({$delfolderids})");
                         foreach ($rows as $row) {
                             $filepath = __ROOT__ . "/Public/uploadfile/images/" . $row['filepath'];
                             if (file_exists($filepath)) {
                                 @unlink($filepath);
                             }
                             $filepath = __ROOT__ . "/Public/uploadfile//thumb/" . $row['filepath'];
                             if (file_exists($filepath)) {
                                 @unlink($filepath);
                             }
                             $attach->where("id={$row['id']}")->delete();
                         }
                     } elseif ($deltype == 0) {
                         //to default dir
                         $attach->where("folderid in ({$delfolderids})")->setField('folderid', 1);
                     }
                     writeFoldersCache();
                     exit('ok');
                 } else {
                     exit('error');
                 }
             } catch (Exception $e) {
                 echo $e;
             }
             break;
         case "deleteAttachment":
             $id = intval(I('get.id'));
             $attach = D('attachments');
             $row = $attach->where("id={$id}")->find();
             if (!empty($row)) {
                 $attachpath = ROOT_PATH . "/Public/uploadfile/images/{$row['filepath']}";
                 if (file_exists($attachpath)) {
                     unlink($attachpath);
                 }
                 $attachpath = ROOT_PATH . "/Public/uploadfile/thumb/{$row['filepath']}";
                 if (file_exists($attachpath)) {
                     unlink($attachpath);
                 }
                 $attach->where("id={$id}")->delete();
                 exit('ok');
             } else {
                 exit('删除失败,文件可能不存在');
             }
             break;
         case "delFiles":
             try {
                 $fileids = I('post.ids');
                 if (isIntArray($fileids)) {
                     $delfileids = implode(",", $fileids);
                     //del files
                     $attach = D('attachments');
                     $attrows = $attach->where("id in ({$delfileids})")->select();
                     foreach ($attrows as $row) {
                         $filepath = ROOT_PATH . "/Public/uploadfile/images/" . $row['filepath'];
                         if (file_exists($filepath)) {
                             @unlink($filepath);
                         }
                         $filepath = ROOT_PATH . "/Public/uploadfile/thumb/" . $row['filepath'];
                         if (file_exists($filepath)) {
                             @unlink($filepath);
                         }
                         $attach->where("id={$row['id']}")->delete();
                     }
                     exit('ok');
                 } else {
                     exit('error');
                 }
             } catch (Exception $e) {
                 echo $e;
             }
             break;
         case "moveFiles":
             try {
                 $fileids = I('post.ids');
                 $targetfolder = intval(I('post.targetfolder'));
                 if (isIntArray($fileids)) {
                     $movefileids = implode(",", $fileids);
                     $attach['folderid'] = $targetfolder;
                     $folders = D('attachments');
                     $folders->where("id in ({$movefileids})")->setField($attach);
                     exit('ok');
                 } else {
                     exit('error');
                 }
             } catch (\Exception $e) {
                 echo $e;
             }
             break;
         default:
             echo '未定义行为';
             break;
     }
 }