CMS  Version 3.9
fileshare_manager.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9  Copyright (c) 2010 Sonjara, Inc
10 
11  Permission is hereby granted, free of charge, to any person
12  obtaining a copy of this software and associated documentation
13  files (the "Software"), to deal in the Software without
14  restriction, including without limitation the rights to use,
15  copy, modify, merge, publish, distribute, sublicense, and/or sell
16  copies of the Software, and to permit persons to whom the
17  Software is furnished to do so, subject to the following
18  conditions:
19 
20  The above copyright notice and this permission notice shall be
21  included in all copies or substantial portions of the Software.
22 
23  Except as contained in this notice, the name(s) of the above
24  copyright holders shall not be used in advertising or otherwise
25  to promote the sale, use or other dealings in this Software
26  without prior written authorization.
27 
28  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35  OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
39 Fakoli::using("fileshare", "document");
40 Fakoli::usingFile("framework/directory_tree.inc");
41 
42 require_once realpath(dirname(__FILE__)."/../document/document_manager.inc");
43 
45 {
46  var $library;
47  var $docs;
48 
50  {
51  $this->library = $library;
52 
53  if($keyword)
54  {
55  $keyword = strtolower($keyword);
56  $constraint = "WHERE LOWER(keywords) like '%$keyword%'";
57  }
58  if ($this->library->document_library_id)
59  {
60  $this->documents = $library->Documents("$constraint ORDER BY title");
61  }
62  else
63  {
64  $this->documents = array();
65  }
66 
67  if(!count($this->documents))
68  {
69  $this->emptyMessage = "There are no documents in {$this->library->name}";
70  if($keyword)
71  {
72  $this->emptyMessage .= " that match the keyword search '{$keyword}'</i>";
73  }
74  $this->emptyMessage .= ".";
75  }
76  }
77 
78  static function libraryTabs($key = "")
79  {
80  $tabs = array(
81  "Details" => "fileshare_library_form",
82  "Add Members" => "fileshare_library_members",
83  "Files" => "fileshare_library_files"
84  );
85 
86  $qs = ($key) ? "document_library_id=$key" : "";
87  $tabs = new TabBar("tabs", $tabs, $qs);
88  $tabs->cssClass = "fileshare";
89  return $tabs;
90  }
91 
92 
98  static function drawMemberSearchForm($library)
99  {
100 ?>
101 <div id="role" style="float: right; width: 30%; z-index: 2; padding: 2px 0">
102 <a class="button" href="#" onclick="new LibraryManager().openPermissionsDialog(<?php echo $library->document_library_id ?>); return false;">Set Global Access</a>
103 </div>
104 <div id="member_search_form">
105 <label for='name'>Add Members</label>
106 <input id='LibraryGroupMembers_form_name' type='text' name='name' autocomplete='off' value='' size='20'/>
107 <br>
108 <div style="float: left; padding-top: 8px; padding-bottom: 5px; margin-bottom: 10px"><span class="ann">Type a user's name or email address to add it to the list.</span></div>
109 </div>
110 <?php
111  }
112 
113  /*
114  * @members - users with fileshare privileges
115  *
116  */
117  static function constructListMembers($members, $document_library_id)
118  {
119  if(count($members) > 0)
120  {
121  foreach($members as $member)
122  {
123  echo FileshareManager::constructListMember($member, $document_library_id);
124  }
125  }
126  }
127 
128  function createUploadedByFacet()
129  {
130  $facet = new MultiSelectFacetFilter("owner_id", array(Document => "{Owner.first_name} {Owner.last_name}"));
131 
132  $facet->dropdownMaxWidth = "160px";
133  $facet->width = "200px";
134  $facet->height = "240px";
135 
136  return $facet;
137  }
138 
139 
140  static function constructListMember($member, $document_library_id)
141  {
142  $text = "<div id=\"user_id_{$member->user_id}\" class=\"list_member\">&nbsp;{$member->getFullName()}&nbsp;";
143  $text .= "<a href=\"#\" class=\"list_action\"";
144  $text .= "onclick=\"new LibraryManager().removeMember($document_library_id, {$member->user_id}); return false;\">&nbsp;\n";
145  $text .= "<span class=\"list_action\">x</span></a>\n";
146  $text .= "</div>\n";
147  return $text;
148  }
149 
150  function formatDocumentTitle($document)
151  {
152  $file = $document->file;
153 
154  $type = getDocType($file);
155  $icon = getDocIcon($file);
156 
157  $library = $document->DocumentLibrary();
158  $size = $library->getFileSize($document);
159 
160  // All users who can view and access the details dialog. Only users with edit access
161  // can edit it; otherwise read only.
162  $details_icon = ($document->fileshareAllowEdit()) ? "icon_edit.png" : "icon_view.png";
163  $details_link = "<a href=\"edit_document?document_id={document_id}\" onclick=\"new LibraryManager().editDocumentDetailsDialog({document_id}); return false;\"><img src=\"/fakoli/images/{$details_icon}\" style=\"border: none;display: inline-block;vertical-align: middle;padding-right: 4px\"></a>\n";
164 
165  if($document->fileshareAllowDelete())
166  {
167  $delete_link .= "<a href=\"delete_document?document_id={document_id}\" onclick=\"new LibraryManager().deleteFile({document_id}); return false;\"><img alt=\"delete\" src=\"/fakoli/images/icon_delete_trash.png\"></a>\n";
168  }
169 
170  return $document->format("<span class='document_title'>{title}</span><br/><img style='display:inline-block;vertical-align: middle' src='$icon' alt='$type'/> <a href='/action/document/download?document_id={document_id}'>Download</a>&nbsp;$size&nbsp;<span style='display: inline-block'>&nbsp;{$details_link}&nbsp;{$delete_link}</span>");
171  }
172 
173  /*
174  * Get the libraries the user is linked to either by
175  * fileshare_user_xref, by being the owner, or by
176  * their role.
177  *
178  * If the library allows visitors read access then
179  * show to nonusers.
180  */
181  static function getSharedLibraries()
182  {
183  global $user;
184 
185  $userXref = new FileshareUserXref();
186 
187 
188  if(!$user)
189  $user = FileshareManager::setVisitor();
190  $roleLibraries = Query::create(DocumentLibrary, "ORDER BY name")->execute();
191  $roleLibraries = filterByRole($roleLibraries, "allow_access");
192 
193  $constraint = "WHERE owner_id=:u or document_library_id in (select document_library_id from {$userXref->table} where user_id=:u)";
194 
195  $libraries = Query::create(DocumentLibrary, "$constraint ORDER BY name")
196  ->bind(":u", $user->user_id)
197  ->execute();
198 
199  if(count($libraries) == 0)
200  $libraries = array();
201 
202  if(count($roleLibraries) > 0)
203  {
204  foreach($roleLibraries as $rLibrary)
205  $libraries[] = $rLibrary;
206  }
207 
208  return removeDuplicates($libraries, "document_library_id");
209  }
210 
211  static function getLibraryLastModified($library)
212  {
213  $documents = Query::create(Document, "WHERE document_library_id=:l ORDER BY last_modified DESC LIMIT 1")
214  ->bind(":l", $library->document_library_id)
215  ->execute();
216 
217  return (count($documents) > 0) ? $documents[0]->format("{last_modified:short}") : null;
218  }
219 
220  static function getLibraryLastModifiedBy($library)
221  {
222  $documents = Query::create(Document, "WHERE document_library_id=:l ORDER BY last_modified DESC LIMIT 1")
223  ->bind(":l", $library->document_library_id)
224  ->execute();
225 
226  $owner = (count($documents) > 0) ? $documents[0]->Owner() : null;
227 
228  return ($owner) ? $owner->getFullName() : null;
229  }
230 
231  /*
232  * Create the identifier by changing library name to
233  * all lower case, replacing blanks with "_" and any
234  * removing all other nonalphnumeric characters.
235  */
236  static function setLibraryIdentifier(&$form)
237  {
238  $library = $form->data;
239 
240  $name = preg_replace("/ /", "_", strtolower($library->name));
241  $library->identifier = preg_replace("/[^A-Za-z0-9_]/", "", $name);
242 
243  $library->filter = new InclusionFilter("identifier");
244  $library->save();
245  }
246 
247  static function onDeleteFileshareLibary($library)
248  {
249  $mgr = new DocumentManager($library);
250  $mgr->deleteDocumentLibrary();
251  redirect("fileshare_libraries");
252  }
253 
254  static function getDocumentAuthor($document)
255  {
256  $owner = $document->Owner();
257  return ($owner) ? $owner->getFullName() : "";
258  }
259 
260  static function getGlobalPermissionOptions()
261  {
262  $options = array(fileshare_only_group_members_read => "Limit Access to Group Members",
263  fileshare_all_site_members_read => "Allow All Site Members to View",
264  fileshare_all_visitors_read => "Allow All Site Members and Site Visitors to View"
265  );
266  return $options;
267  }
268 
269  static function setVisitor()
270  {
271  $userClass = UserManager::getUserClass();
272  $user = new $userClass();
273  $user->user_id = 0;
274  $user->role = "visitor";
275 
276  return $user;
277  }
278 
286  static function deleteUser($user)
287  {
288  $pk = $user->getPrimaryKey();
289  $user_id = $user->$pk;
290 
291  trace("Component fileshare is deleting objects dependent on user_id {$user_id}", 3);
292 
293  $xref = new FileshareUserXref();
294  $xref->delete("WHERE user_id={$user_id}");
295 
296  return $user;
297  }
298 
299  static function upgradeComponent($version)
300  {
301  $mgr = new FileshareUpgradeManager();
302  $mgr->upgrade($version);
303  }
304 }
305 ?>
$constraint
$table emptyMessage
$tabs
$helpTree style
Definition: tree.inc:46
$imageUpload size
Definition: image_form.inc:68
$form action
Definition: edit.inc:67
$icon
Definition: upload.inc:92
The DocumentManager class provides the core API and management functions for uploading documents and ...
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static usingFile()
Uses the specified framework file(s) from the framework directory.
Definition: core.inc:369
static drawMemberSearchForm($library)
For Members tab.
FileshareManager($library, $keyword="")
static libraryTabs($key="")
$d document_id
Definition: download.inc:67
text align
Definition: redirects.inc:13