CMS  Version 3.9
move_documents.inc
Go to the documentation of this file.
1 <?php
2 Fakoli::using("document");
3 $document_library_id = checkNumeric($_GET["document_library_id"]);
4 $document_ids = checkNumericList($_GET["document_ids"]);
5 
7 {
8  Fakoli::end("Missing Parameter");
9 }
10 
12 if (!$library->allowManageFiles())
13 {
14  Fakoli::end("Permission Denied");
15 }
16 
19 
20 $form = new AutoForm($documentMove, "POST", "/action/document/move_documents?document_library_id={$document_library_id}&document_ids={$document_ids}");
21 $form->ajaxSubmit("function(response) { moveDocumentsResponse(response); }");
22 
23 $form->related(DocumentLibrary, "WHERE document_library_id={$document_library_id}", "{name}", "from", "Move From", false, false);
24 $form->related(DocumentLibrary, "WHERE document_library_id!={$document_library_id} ORDER BY name", "{name}", "to", "Move To", false, false);
25 $form->readonly("from");
26 $form->submitLabel = "Move Documents";
27 $form->button("Cancel", "ModalDialog.closeAllDialogs(); return true", null, true);
28 
29 $form->customSaveHandler = function($form) use ($library, $document_ids)
30 {
31  $to = new DocumentLibrary($form->data->to);
32 
33  $docs = Query::create(Document, "WHERE document_id IN ($document_ids)")->execute();
34 
35  foreach($docs as $doc)
36  {
37  $fromPath = $library->getLibraryDirectory().DIRECTORY_SEPARATOR.$doc->file;
38  $toPath = $to->getLibraryDirectory().DIRECTORY_SEPARATOR.$doc->file;
39  rename($fromPath, $toPath);
40  $doc->document_library_id = $to->document_library_id;
41  $doc->save();
42  }
43  return true;
44 };
45 
46 if ($method == "POST")
47 {
48  if ($form->save())
49  {
50  Fakoli::notifyOnNextPage("Documents Moved");
51  Fakoli::end("OK");
52  }
53  else
54  {
55  Fakoli::end($form->msg);
56  }
57 }
58 
59 $script .= $form->writeScript();
60 $form->drawForm();
This class maps the publication table.
Definition: document.inc:43
static notifyOnNextPage($message, $blocking=false, $button="OK", $onClick="null")
Schedules a notification message to be displayed to the user at the next full page load.
Definition: core.inc:1223
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static end($message="")
Use this method to terminate execution of a script instead of using the php keywords exit() or die().
Definition: core.inc:1149
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
if(! $library->allowManageFiles()) $documentMove
$document_ids
if(! $document_library_id||! $document_ids) $library
$document_library_id
if($method=="POST") $script