documents.php

Go to the documentation of this file.
00001 <?php
00021 $modules_names[] = "Documents";
00022 $modules_versions[] = "0.1";
00023 $modules_descriptions[] = "A crosslinked story-tree style documents manager";
00024 
00025 $modules_setup[] = "modulesetup_documents";
00026 $profilemodules[] = "profilemodule_documents";
00027 
00028 $modules[] = "parse_documents";
00029 
00030 $page_help["&#92;document(txt1)"] = "Show a single document, with the id txt1";
00031 $page_help["&#92;documentlink(txt1)"] = "Show a link to a document with the id txt1. The link text will be the document's title.";
00032 $page_help["&#92;documentrating(txt1)"] = "Show a list of documents with the rating with the id txt1";
00033 $page_help["&#92;documents()"] = "Show a list of documents. This is not normally used by users, in stead it is used internally by the documents module.";
00034 
00035 $dox_infofolder = "$module_folder/documents/content/info";
00036 if( !is_dir($dox_infofolder) )
00037         RecursiveMkdir( $dox_infofolder );
00038 $dox_datafolder = "$module_folder/documents/content/data";
00039 if( !is_dir($dox_datafolder) )
00040         RecursiveMkdir( $dox_datafolder );
00041 $dox_categoryfolder = "$module_folder/documents/categories";
00042 if( !is_dir($dox_categoryfolder) )
00043         RecursiveMkdir( $dox_categoryfolder );
00044 
00045 // Set up some default options
00046 $dox_options = array(
00047         "page_id" => 12, // If the user's not set anything up yet - show him the way back to module setup!
00048         "nextID" => 0, // The first document ID is zero, meaning that the first one actually returned by dox_nextID is 1
00049         "viewLevel" => 0, // Everybody can view
00050         "commentLevel" => 1, // Registered users can comment
00051         "editLevel" => 4, // Owner and admin only can edit
00052         "listingColumns" => array("title","mdate","authors"), // What columns to show in listings by default
00053         "rating" => 0, // Default rating, from the list below
00054         "ratings" => array(
00055                 0 => "G rated",
00056                 1 => "PG-13 rated",
00057                 2 => "18 rated",
00058                 3 => "X rated")
00059         );
00060 $dox_optionfile = "$module_folder/documents/options.php";
00061 
00062 if( file_exists( $dox_optionfile ) )
00063         include( $dox_optionfile );
00064 
00065 if(!array_key_exists("listingColumns", $dox_options))
00066         $dox_options["listingColumns"] = array("title","date","authors"); // What columns to show in listings by default
00067 
00068 $dox_listingcolumns = array(
00069         "title" => i18n("Title"),
00070         "date" => i18n("Creation date"),
00071         "mdate" => i18n("Last modified"),
00072         "rating" => i18n("Rating"),
00073         "owner" => i18n("Owner"),
00074         "authors" => i18n("Authors"));
00075 
00077 class dox_document extends lockableClass
00078 {
00079         var $id;                           
00080         var $createdate;                   
00081         var $modifydate;                   
00082         var $blurb;                        
00083         var $content;                      
00084         var $comments;                     
00085         var $commentCount;                 
00086         var $published;                    
00087         
00088         var $backwardrel;                  
00089         var $forwardrel;                   
00090         
00091         var $owner;                        
00092         var $viewLevel;                    
00093         var $commentLevel;                 
00094         var $editLevel;                    
00095         
00096         var $authors;                      
00097         var $categories;                   
00098         var $rating;                       
00099         
00101         var $edit = false;                 
00102         var $infofile;                     
00103         var $datafile;                     
00104         
00111         function dox_document( $id = 0, $document = "" )
00112         {
00113                 global $dox_infofolder, $dox_datafolder;
00114                 
00115                 $this->id = $id;
00116                 
00117                 $this->infofile = "$dox_infofolder/$id.php";
00118                 $this->datafile = "$dox_datafolder/$id.php";
00119                 $this->lockfile = "$dox_infofolder/$id.lock";
00120                 if( file_exists( $this->infofile ) )
00121                         include( $this->infofile );
00122                 
00123                 $this->title = $document["title"];
00124                 $this->createdate = $document["createdate"];
00125                 $this->modifydate = $document["modifydate"];
00126                 $this->blurb = $document["blurb"];
00127                 $this->published = $document["published"];
00128                 $this->backwardrel = $document["backwardrel"];
00129                 $this->forwardrel = $document["forwardrel"];
00130                 $this->owner = $document["owner"];
00131                 $this->viewLevel = $document["viewLevel"];
00132                 $this->commentLevel = $document["commentLevel"];
00133                 $this->comments = $document["comments"];
00134                 $this->commentCount = $document["commentCount"];
00135                 $this->editLevel = $document["editLevel"];
00136                 $this->authors = $document["authors"];
00137                 $this->categories = $document["categories"];
00138                 $this->rating = $document["rating"];
00139                 
00140                 // If this is the case, we are creating a new document
00141                 if( $id == 0 && is_array( $document ) )
00142                 {
00143                         // Get the ID for the new document
00144                         $this->id = dox_nextID();
00145                         // Remake the filenames with this new ID
00146                         $this->infofile = "$dox_infofolder/" . $this->id . ".php";
00147                         $this->datafile = "$dox_datafolder/" . $this->id . ".php";
00148                         // Save this document - The notification is for the containing rating, someone may well have subscribed to that
00149                         $this->save( i18n("The document was created") );
00150                         // Add it to the all documents cache list
00151                         $allDocs = new dox_alldocs();
00152                         $allDocs->addDocument($this->id, $this->title, $this->owner, $this->authors, $this->createdate, $this->modifydate, $this->rating, $this->blurb, true);
00153                 }
00154         }
00155         
00159         function loadContent()
00160         {
00161                 if( file_exists( $this->datafile ) )
00162                         include( $this->datafile );
00163         }
00164         
00170         function saveContent( $content = "" )
00171         {
00172                 if( $content != "" )
00173                         $this->content = $content;
00174                 
00175                 if( file_exists( $this->datafile ) )
00176                         unlink( $this->datafile );
00177                 
00178                 file_put_contents( $this->datafile, array_export( $this->content, "this->content" ) );
00179         }
00180         
00187         function save( $theMessage = "", $commenter = "" )
00188         {
00189                 global $subscriptions;
00190                 
00191                 // Update info in global documents index and save
00192                 $allDocs = new dox_alldocs();
00193                 $allDocs->documents[$this->id]["title"] = $this->title;
00194                 $allDocs->documents[$this->id]["blurb"] = $this->blurb;
00195                 $allDocs->documents[$this->id]["owner"] = $this->owner;
00196                 $allDocs->documents[$this->id]["authors"] = $this->authors;
00197                 $allDocs->documents[$this->id]["date"] = $this->createdate;
00198                 $allDocs->documents[$this->id]["mdate"] = $this->modifydate;
00199                 $allDocs->documents[$this->id]["rating"] = $this->rating;
00200                 $allDocs->documents[$this->id]["published"] = $this->published;
00201                 $allDocs->documents[$this->id]["orphaned"] = ( count($this->categories) > 0 ) ? false : true;
00202                 $allDocs->save();
00203                 
00204                 // Save self
00205                 $document["title"] = $this->title;
00206                 $document["createdate"] = $this->createdate;
00207                 $document["modifydate"] = $this->modifydate;
00208                 $document["blurb"] = $this->blurb;
00209                 $document["published"] = $this->published;
00210                 $document["owner"] = $this->owner;
00211                 $document["viewLevel"] = $this->viewLevel;
00212                 $document["commentLevel"] = $this->commentLevel;
00213                 $document["commentCount"] = $this->commentCount;
00214                 $document["editLevel"] = $this->editLevel;
00215                 $document["rating"] = $this->rating;
00216                 $document["comments"] = $this->comments;
00217                 $document["backwardrel"] = $this->backwardrel;
00218                 $document["forwardrel"] = $this->forwardrel;
00219                 $document["authors"] = $this->authors;
00220                 $document["categories"] = $this->categories;
00221                 
00222                 if( file_exists( $this->infofile ) )
00223                         unlink( $this->infofile );
00224                 
00225                 if( $commenter != "" || $theMessage != "" )
00226                 {
00227                         if( $commenter != "" )
00228                         {
00229                                 $subject = i18n("The document \"##0##\" was commented by ##0##", array( $this->title, getUserInfo($commenter, "name") ) );
00230                                 $message = i18n("A new comment was created by ##0## on the document \"##1##\". The comment was:##2####3##", array( getUserInfo($commenter, "name"), $this->title, "\n$theMessage", "\n---" . globalIDtoURL("documents/view/" . $this->id) ) );
00231                         }
00232                         else if ( $theMessage != "" )
00233                         {
00234                                 $subject = i18n("The details for \"##0##\" was edited by ##0##", array( $this->title, getUserInfo(currentUser(), "name") ) );
00235                                 $message = i18n("The deils for the change by ##0## on the document \"##1##\" are as follows:##2####3##", array( getUserInfo($commenter, "name"), $this->title, "\n$theMessage", "\n---" . globalIDtoURL("documents/view/" . $this->id) ) );
00236                         }
00237                         // Notify categories...
00238                         // Notify rating...
00239                         $subscriptions->handle( "documents/rating/" . $this->rating, $this->owner, $this->viewLevel, $subject, $message );
00240                         // Notify document
00241                         $subscriptions->handle( "documents/view/" . $this->id, $this->owner, $this->viewLevel, $subject, $message );
00242                 }
00243                 
00244                 file_put_contents( $this->infofile, array_export( $document, "document" ) );
00245         }
00246         
00252         function delete()
00253         {
00254                 if( userAllows( $this->owner, $this->editLevel ) )
00255                 {
00256                         // Delete own datafiles
00257                         if( file_exists( $this->infofile ) )
00258                                 unlink( $this->infofile );
00259                         if( file_exists( $this->datafile ) )
00260                                 unlink( $this->datafile );
00261                         
00262                         // Subscriptions need removing
00263                         global $subscriptions;
00264                         $subscriptions->removeGlobalID( "documents/view/" . $this->id );
00265                         
00266                         // Remove from alldocs cache
00267                         $allDocs = new dox_alldocs();
00268                         unset( $allDocs->documents[$this->id] );
00269                         $allDocs->save();
00270                         
00271                         return true;
00272                 }
00273                 else
00274                         return false;
00275         }
00276         
00280         function addToCategory( $category )
00281         {
00282                 // Check if doc is in orphaned documents listing
00283                         // Remove doc from orphaned documents listing if so
00284                         // Save orphaned documents listing
00285                 // Add document to category
00286                 // Save category
00287                 // Add category to document
00288                 // Save document
00289         }
00290         
00294         function removeFromCategory( $category )
00295         {
00296                 // Remove doc from category
00297                 // Save category
00298                 // Remove category from document
00299                 // Save document
00300                 // Check wether document is categorised
00301                         // If not, add to orphaned documents listing
00302                         // Save orphaned documents listing
00303         }
00304         
00310         function userCanEdit()
00311         {
00312                 if( userIsAllowed(currentUser(), "global_admin") )
00313                         return true;
00314                 
00315                 if( userAllows( $this->owner, $this->editLevel ) )
00316                         return true;
00317                 
00318                 if( in_array(currentUser(), $this->authors) )
00319                         return true;
00320                 
00321                 return false;
00322         }
00323         
00329         function renderEditor()
00330         {
00331                 global $globalID, $page_title, $dox_options, $permissionlevels_array;
00332                 $this->loadContent();
00333                 $allDocs = new dox_alldocs();
00334                 
00335                 $splitID = explode( "/", $globalID );
00336                 
00337                 switch( $splitID[3] )
00338                 {
00339                 case "deleteprev":
00340                 case "deletenext":
00341                         $otherDoc = new dox_document( $splitID[4] );
00342                         if( $_REQUEST["confirmDelete"] == "true" )
00343                         {
00344                                 if( $this->lock() )
00345                                 {
00346                                         $this->load();
00347                                         $otherDoc->load();
00348                                         
00349                                         if( $splitID[3] == "deleteprev" )
00350                                         {
00351                                                 unset( $this->backwardrel[array_search($splitID[4], $this->backwardrel)] );
00352                                                 unset( $otherDoc->forwardrel[array_search($this->id, $this->forwardrel)] );
00353                                         }
00354                                         else
00355                                         {
00356                                                 unset( $this->forwardrel[array_search($splitID[4], $this->forwardrel)] );
00357                                                 unset( $otherDoc->backwardrel[array_search($this->id, $this->backwardrel)] );
00358                                         }
00359                                         
00360                                         $this->save( i18n("The document is no longer associated with \"##0##\" - ##1##", array($otherDoc->title, globalIDtoURL("documents/view/" . $this->id ) ) ) );
00361                                         $otherDoc->save( i18n("The document is no longer associated with \"##0##\" - ##1##", array($this->title, globalIDtoURL("documents/view/" . $otherDoc->id ) ) ) );
00362                                         
00363                                         $this->unlock();
00364                                         $otherDoc->unlock();
00365                                 }
00366                                 
00367                                 header( "Location: " . globalIDtoURL( "documents/edit/" . $this->id ) );
00368                         }
00369                         
00370                         $title = ($splitID[3] == "deleteprev") ? i18n("Remove previous document") : i18n("Remove next document");
00371                         $renderedContent = renderInformationBox($title,
00372                                 i18n("Are you sure you wish to remove the link between the documents ##0## and ##1##", array("&quot;" . $this->title . "&quot;", "&quot;" . $otherDoc->title . "&quot;")) . "<div class=\"wikicenteralign\">" .
00373                                 drawCommand( i18n("Confirm removal"), i18n("Confirm that you wish to remove the link between the two documents"), globalIDtoURL("documents/edit/" . $this->id . "/" . $splitID[3] . "/" . $splitID[4], array("confirmDelete" => "true")) ) . " " .
00374                                 drawCommand( i18n("Abort removal"), i18n("Abort the removal process"), globalIDtoURL("documents/edit/" . $this->id) ) . "</div>"
00375                                 , false);
00376                         break;
00377                 case "addprev":
00378                 case "addnext":
00379                         $panel = new optionsPanel("");
00380                         $panel->saveTitle = i18n("Add document");
00381                         $panel->showHeader = false;
00382                         
00383                         $values["document"] = $_POST["document"] ? $_POST["document"] : "";
00384                         
00385                         $availableDocs = array();
00386                         foreach( $allDocs->documents as $key => $value )
00387                         {
00388                                 if(
00389                                         ( $splitID[3] == "addprev" && $value["id"] != $this->id && !in_array($value["id"], $this->backwardrel) ) ||
00390                                         ( $splitID[3] == "addnext" && $value["id"] != $this->id && !in_array($value["id"], $this->forwardrel) )
00391                                         )
00392                                         $availableDocs[$value["id"]] = $value["title"];
00393                         }
00394                         
00395                         $panel->addOption(
00396                                 i18n("Document to add"),
00397                                 i18n("Select the document you wish to add to the list of documents"),
00398                                 $values["document"],
00399                                 "document",
00400                                 "select",
00401                                 $availableDocs);
00402                         
00403                         if( $_POST["saveOptions"] )
00404                         {
00405                                 $otherDoc = new dox_document( $values["document"] );
00406                                 
00407                                 if( $this->lock() )
00408                                 {
00409                                         $this->load();
00410                                         $otherDoc->load();
00411                                         
00412                                         if( $splitID[3] == "addprev" )
00413                                         {
00414                                                 $this->backwardrel[] = $values["document"];
00415                                                 $otherDoc->forwardrel[] = $this->id;
00416                                         }
00417                                         else
00418                                         {
00419                                                 $this->forwardrel[] = $values["document"];
00420                                                 $otherDoc->backwardrel[] = $this->id;
00421                                         }
00422                                         
00423                                         $this->save( i18n("The document was associated with \"##0##\" - ##1##", array($otherDoc->title, globalIDtoURL("documents/view/" . $this->id ) ) ) );
00424                                         $otherDoc->save( i18n("The document was associated with \"##0##\" - ##1##", array($this->title, globalIDtoURL("documents/view/" . $otherDoc->id ) ) ) );
00425                                         
00426                                         $this->unlock();
00427                                         $otherDoc->unlock();
00428                                 }
00429                                 
00430                                 header( "Location: " . globalIDtoURL( "documents/edit/" . $this->id ) );
00431                         }
00432                         
00433                         $title = ($splitID[3] == "addprev") ? i18n("Add previous document") : i18n("Add next document");
00434                         $renderedContent = renderInformationBox($title, $panel->render(), false);
00435                         break;
00436                 case "removeauthor":
00437                         if( strpos( $this->authors[$splitID[4]], "\n" ) === false )
00438                                 $authorName = parse_profilelinks("%%" . $this->authors[$splitID[4]] . "%%");
00439                         else
00440                                 $authorName = strtok($this->authors[$splitID[4]], "\n" );
00441                         
00442                         if( $_REQUEST["confirmDelete"] == "true" )
00443                         {
00444                                 if( $this->lock() )
00445                                 {
00446                                         $this->load();
00447                                         unset( $this->authors[$splitID[4]] );
00448                                         $this->save( i18n("The author ##0## was removed from the document", array($authorName) ) );
00449                                         $this->unlock();
00450                                 }
00451                                 
00452                                 header( "Location: " . globalIDtoURL( "documents/edit/" . $this->id ) );
00453                         }
00454                         
00455                         $title = ($splitID[3] == "deleteprev") ? i18n("Remove previous document") : i18n("Remove next document");
00456                         
00457                         $renderedContent = renderInformationBox(i18n("Remove author"),
00458                                 i18n("Are you sure you wish to remove the author ##0## from the document ##1##", array($authorName, "&quot;" . $this->title . "&quot;")) . "<div class=\"wikicenteralign\">" .
00459                                 drawCommand( i18n("Confirm removal"), i18n("Confirm that you wish to remove the author from the document"), globalIDtoURL("documents/edit/" . $this->id . "/removeauthor/" . $splitID[4], array("confirmDelete" => "true")) ) . " " .
00460                                 drawCommand( i18n("Abort removal"), i18n("Abort the removal process"), globalIDtoURL("documents/edit/" . $this->id) ) . "</div>"
00461                                 , false);
00462                         break;
00463                         break;
00464                 case "addauthor":
00465                         $panel = new optionsPanel("");
00466                         $panel->saveTitle = i18n("Add author");
00467                         $panel->showHeader = false;
00468                         
00469                         $values["user"] = $_POST["user"] ? $_POST["user"] : "";
00470                         $values["name"] = $_POST["name"] ? $_POST["name"] : "";
00471                         $values["url"] = $_POST["url"] ? $_POST["url"] : "";
00472                         
00473                         $availableDocs = array();
00474                         $allUsers = allUsersArray();
00475                         foreach( $allUsers as $key => $value )
00476                                 if( !in_array($value, $this->authors) )
00477                                         $availableUsers[$value] = getUserInfo( $value, "name" );
00478                         
00479                         if( count( $availableUsers ) > 0 )
00480                         {
00481                                 $panel->addHeader( i18n("Either select a user"), "user" );
00482                                 $panel->addOption(
00483                                         i18n("Author to add"),
00484                                         i18n("Select the author you wish to add to the list of authors"),
00485                                         $values["user"],
00486                                         "user",
00487                                         "select",
00488                                         $availableUsers);
00489                                 $panel->addHeader( i18n("Or type in the author's details"), "external" );
00490                         }
00491                         $panel->addOption(
00492                                 i18n("Name"),
00493                                 i18n("The author's name"),
00494                                 $values["name"],
00495                                 "name",
00496                                 "text");
00497                         $panel->addOption(
00498                                 i18n("URL"),
00499                                 i18n("Type in a valid URL for this author, for example http://www.somesite.com/ or mailto:user@email.com"),
00500                                 $values["url"],
00501                                 "url",
00502                                 "text");
00503                         
00504                         if( $_POST["saveOptions"] )
00505                         {
00506                                 if( $values["name"] != "" )
00507                                         $author = $values["name"] . "\n" . $values["url"];
00508                                 else
00509                                         $author = $values["user"];
00510                                 
00511                                 if( $this->lock() )
00512                                 {
00513                                         $this->load();
00514                                         $this->authors[] = $author;
00515                                         $this->save( i18n("The author ##0## was added to the document", array($author) ) );
00516                                         $this->unlock();
00517                                 }
00518                                 
00519                                 header( "Location: " . globalIDtoURL( "documents/edit/" . $this->id ) );
00520                         }
00521                         
00522                         $title = i18n("Add author");
00523                         $renderedContent = renderInformationBox($title, $panel->render(), false);
00524                         break;
00525                 default:
00526                         $panel = new optionsPanel("");
00527                         $panel->saveTitle = i18n("Save document");
00528                         $panel->showHeader = false;
00529                         
00530                         $values["title"] = $_POST["title"] == "" ? $this->title : stripslashes($_POST["title"]);
00531                         $values["blurb"] = $_POST["blurb"] == "" ? $this->blurb : stripslashes($_POST["blurb"]);
00532                         $values["rating"] = $_POST["rating"] == "" ? $this->rating : $_POST["rating"];
00533                         $values["viewLevel"] = $_POST["viewLevel"] == "" ? $this->viewLevel : $_POST["viewLevel"];
00534                         $values["commentLevel"] = $_POST["commentLevel"] == "" ? $this->commentLevel : $_POST["commentLevel"];
00535                         $values["editLevel"] = $_POST["editLevel"] == "" ? $this->editLevel : $_POST["editLevel"];
00536                         $values["content"] = $_POST["content"] == "" ? $this->content : stripslashes($_POST["content"]);
00537                         $values["owner"] = $_POST["owner"] == "" ? $this->owner : $_POST["owner"];
00538                         
00539                         $panel->addOption(
00540                                 i18n("Title"),
00541                                 i18n("Title of the new document"),
00542                                 $values["title"],
00543                                 "title",
00544                                 "text");
00545                         $panel->addOption(
00546                                 i18n("Blurb"),
00547                                 i18n("A short description of the document"),
00548                                 $values["blurb"],
00549                                 "blurb",
00550                                 "text");
00551                         $panel->addOption(
00552                                 i18n("Rating"),
00553                                 i18n("What rating does this document fall under?"),
00554                                 $values["rating"],
00555                                 "rating",
00556                                 "select",
00557                                 $dox_options["ratings"]);
00558                         
00559                         if( userIsAllowed(currentUser(), "global_admin") )
00560                                 $panel->addOption(
00561                                         i18n("Document owner"),
00562                                         i18n("Who owns this document?"),
00563                                         $values["owner"],
00564                                         "owner",
00565                                         "select",
00566                                         allUsersArray(true, true));
00567                         
00568                         $panel->addOption(
00569                                 i18n("Viewing allowance level"),
00570                                 i18n("Who except ##0## is allowed to view this document?", array(getUserInfo($values["owner"], "name"))),
00571                                 $values["viewLevel"],
00572                                 "viewLevel",
00573                                 "select",
00574                                 $permissionlevels_array);
00575                         $panel->addOption(
00576                                 i18n("Commenting allowance level"),
00577                                 i18n("Who except ##0## is allowed to comment on this document?", array(getUserInfo($values["owner"], "name"))),
00578                                 $values["commentLevel"],
00579                                 "commentLevel",
00580                                 "select",
00581                                 $permissionlevels_array);
00582                         $panel->addOption(
00583                                 i18n("Editing allowance level"),
00584                                 i18n("Who except ##0## is allowed to edit this document?", array(getUserInfo($values["owner"], "name"))),
00585                                 $values["editLevel"],
00586                                 "editLevel",
00587                                 "select",
00588                                 $permissionlevels_array);
00589                         $panel->addOption(
00590                                 i18n("Document contents"),
00591                                 "",
00592                                 $values["content"],
00593                                 "content",
00594                                 "pagedata");
00595                         
00596                         if( $_POST["saveOptions"] )
00597                         {
00598                                 if( $this->lock() )
00599                                 {
00600                                         $this->load();
00601                                         
00602                                         $this->title = $values["title"];
00603                                         $this->modifydate = time();
00604                                         $this->blurb = $values["blurb"];
00605                                         $this->viewLevel = $values["viewLevel"];
00606                                         $this->commentLevel = $values["commentLevel"];
00607                                         $this->editLevel = $values["editLevel"];
00608                                         $this->rating = $values["rating"];
00609                                         
00610                                         if( userIsAllowed(currentUser(), "global_admin") )
00611                                                 $this->owner = $values["owner"];
00612                                         
00613                                         $theReason = i18n("The main document details were changed.");
00614                                         if( $this->content != $values["content"] )
00615                                                 $theReason .= " " . i18n("The contents of the document itself were also changed.");
00616                                         $this->content = $values["content"];
00617                                         
00618                                         $this->save( $theReason );
00619                                         $this->saveContent();
00620                                         
00621                                         $this->unlock();
00622                                 }
00623                                 
00624                                 header("Location: " . globalIDtoURL( "documents/view/" . $this->id ) );
00625                         }
00626                         
00627                         // Title
00628                         $page_title = $this->title;
00629                         // Navigator - previous and next links side-by-side, with stats between them (rating, letter count, word count, lix, categories in list (with links))
00630                         $prevDocs = "";
00631                         foreach( $this->backwardrel as $key => $value )
00632                                 $prevDocs .= "
00633                                 <a href=\"" . globalIDtoURL("documents/edit/" . $this->id . "/deleteprev/$value") . "\">" . i18n("Remove ##0##", array($allDocs->documents[$value]["title"])) . "</a><br />";
00634                         if( $prevDocs == "" )
00635                                 $prevDocs = i18n("No previous documents") . "<br />";
00636                         $prevDocs .= drawCommand(i18n("Add previous document"), i18n("Add a document to the list of documents to read before this one"), globalIDtoURL("documents/edit/" . $this->id . "/addprev"));
00637                                 
00638                         $nextDocs = "";
00639                         foreach( $this->forwardrel as $key => $value )
00640                                 $nextDocs .= "
00641                                 <a href=\"" . globalIDtoURL("documents/edit/" . $this->id . "/deletenext/$value") . "\">" . i18n("Remove ##0##", array($allDocs->documents[$value]["title"])) . "</a><br />";
00642                         if( $nextDocs == "" )
00643                                 $nextDocs = i18n("No next documents") . "<br />";
00644                         $nextDocs .= drawCommand(i18n("Add next document"), i18n("Add a document to the list of documents to read next"), globalIDtoURL("documents/edit/" . $this->id . "/addnext"));
00645                         
00646                         $firstAuthor = true;
00647                         foreach( $this->authors as $key => $value )
00648                         {
00649                                 if( $firstAuthor == false )
00650                                         $renderedAuthors .= ", ";
00651                                 else
00652                                         $firstAuthor = false;
00653                                 
00654                                 if( strpos($value, "\n") === false )
00655                                         $renderedAuthors .= "<a href=\"" . globalIDtoURL("documents/edit/" . $this->id . "/removeauthor/" . $key) . "\" >" . getUserInfo($value, "name") . "</a>";
00656                                 else
00657                                 {
00658                                         list( $authorName, $authorURL ) = explode( "\n", $value);
00659                                         $renderedAuthors .= "<a href=\"" . globalIDtoURL("documents/edit/" . $this->id . "/removeauthor/" . $key) . "\" >" . $authorName . "</a>";
00660                                 }
00661                         }
00662                         if( $firstAuthor == false )
00663                                 $renderedAuthors .= ", ";
00664                         $renderedAuthors .= drawCommand( i18n("Add author"), i18n("Add an author to the list of authors"), globalIDtoURL("documents/edit/" . $this->id . "/addauthor"));
00665                         
00666                         $wordcount = 1;
00667                         $lettercount = 1;
00668                         $lix = $lettercount / $wordcount;
00669                         $categorylist = i18n("(not implemented)");
00670                         
00671                         $docStats = "
00672                         <div class=\"documents-viewdoc-navigator-stats\">" . i18n("Authors: ##0##", array($renderedAuthors)) . "</div>
00673                         <div class=\"documents-viewdoc-navigator-stats\">" . i18n("Categories: ##0##", array($categorylist)) . "</div>";
00674                         
00675                         $navigator = "
00676                         <table class=\"documents-viewdoc-navigator\">
00677                         <tr class=\"documents-viewdoc-navigator\">
00678                                 <td class=\"documents-viewdoc-navigator-previous\">$prevDocs</td>
00679                                 <td class=\"documents-viewdoc-navigator-stats\">$docStats</td>
00680                                 <td class=\"documents-viewdoc-navigator-next\">$nextDocs</td>
00681                         </tr>
00682                         </table>";
00683                         $renderedContent .= $navigator;
00684                         // Content
00685                         $renderedContent .= "$editLink<div class=\"documents-viewdoc-content\">" . $panel->render() . "</div>";
00686                         // Navigator again (same as above)
00687                         $renderedContent .= $navigator;
00688                 }
00689                 return "<form action=\"" . thisPageURL() . "\" method=\"POST\">" . $renderedContent . "</form>";
00690         }
00691         
00699         function renderBlock($userColumns)
00700         {
00701                 global $dox_options;
00702                 $renderedData = "";
00703                 if( $this->published || $this->edit )
00704                 {
00705                         $renderedData = "
00706                         <tr class=\"documents-table\">";
00707                         if( in_array( "title", $userColumns ) )
00708                                 $renderedData .= "
00709                                 <td class=\"documents-table\">" . $this->title . " (" . $this->commentCount . ")<small class=\"comment\">" . $this->blurb . "</small></td>";
00710                         if( in_array( "date", $userColumns ) )
00711                                 $renderedData .= "
00712                                 <td class=\"documents-table\">" . formatTime($this->createdate) . "</td>";
00713                         if( in_array( "mdate", $userColumns ) )
00714                                 $renderedData .= "
00715                                 <td class=\"documents-table\">" . formatTime($this->modifydate) . "</td>";
00716                         if( in_array( "rating", $userColumns ) )
00717                                 $renderedData .= "
00718                                 <td class=\"documents-table\">" . $dox_options["ratings"][$this->rating] . "</td>";
00719                         if( in_array( "owner", $userColumns ) )
00720                                 $renderedData .= "
00721                                 <td class=\"documents-table\">" . parse_profilelinks("%%" . $this->owner . "%%", "documents") . "</td>";
00722                         // The view command is ALWAYS shown
00723                         if( in_array( "authors", $userColumns ) )
00724                         {
00725                                 $renderedData .= "
00726                                 <td class=\"documents-table\">";
00727                                 $firstAuthor = "";
00728                                 foreach( $this->authors as $key => $value )
00729                                 {
00730                                         $renderedData .= $firstAuthor;
00731                                         $renderedData .= parse_profilelinks("%%" . $value . "%%", "documents");
00732                                         $firstAuthor = ", ";
00733                                 }
00734                                 $renderedData .= "</td>";
00735                         }
00736                         $renderedData .= "
00737                                 <td class=\"documents-table-right\">" . drawCommand(i18n("View ##0##", array("&raquo;")), i18n("View ##0##", array($this->title)), globalIDtoURL("documents/view/" . $this->id) ) . "</td>
00738                         </tr>";
00739                 }
00740                 return $renderedData;
00741         }
00742         
00748         function render()
00749         {
00750                 global $page_title, $dox_options, $subscriptions;
00751                 $trail = new breadcrumbs( i18n("Documents"), globalIDtoURL("documents") );
00752                 $trail->addCrumb( $dox_options["ratings"][$this->rating], globalIDtoURL("documents/rating/" . $this->rating) );
00753                 $trail->addCrumb( $this->title, globalIDtoURL("documents/view/" . $this->id) );
00754                 if( $this->userCanEdit() && $this->edit )
00755                         $renderedContent = $this->renderEditor();
00756                 else
00757                 {
00758                         $this->loadContent();
00759                         $allDocs = new dox_alldocs();
00760                         // Title
00761                         $page_title = $this->title;
00762                         // Navigator - previous and next links side-by-side, with stats between them (rating, letter count, word count, lix, categories in list (with links))
00763                         $prevDocs = "";
00764                         foreach( $this->backwardrel as $key => $value )
00765                                 $prevDocs .= "
00766                                 <a href=\"" . globalIDtoURL("documents/view/" . $value) . "\" class=\"documents-viewdoc-navigator-previous\">" . $allDocs->documents[$value]["title"] . "</a><br />";
00767                         if( $prevDocs == "" )
00768                                 $prevDocs = i18n("No previous documents") . "<br />";
00769                                 
00770                         $nextDocs = "";
00771                         foreach( $this->forwardrel as $key => $value )
00772                                 $nextDocs .= "
00773                                 <a href=\"" . globalIDtoURL("documents/view/" . $value) . "\" class=\"documents-viewdoc-navigator-next\">" . $allDocs->documents[$value]["title"] . "</a><br />";
00774                         if( $nextDocs == "" )
00775                                 $nextDocs = i18n("No next documents") . "<br />";
00776                         
00777                         $wordcount = count_words($this->content);
00778                         $lettercount = strlen($this->content);
00779                         $categorylist = i18n("(not implemented)");
00780                         
00781                         $firstAuthor = true;
00782                         foreach( $this->authors as $key => $value )
00783                         {
00784                                 if( $firstAuthor == false )
00785                                         $renderedAuthors .= ", ";
00786                                 else
00787                                         $firstAuthor = false;
00788                                 
00789                                 if( strpos($value, "\n") === false )
00790                                         $renderedAuthors .= parse_profilelinks( "%%$value%%", "documents" );
00791                                 else
00792                                 {
00793                                         list( $authorName, $authorURL ) = explode( "\n", $value);
00794                                         $renderedAuthors .= "<a href=\"" . $authorURL . "\" >" . $authorName . "</a>";
00795                                 }
00796                         }
00797                         
00798                         $commenthandler = new commentHandler($this->comments, $this->owner, $this->commentLevel, $this->editLevel);
00799                         $commenthandler->thisPageURL = globalIDtoURL( "documents/view/" . $this->id );
00800                         if( $commenthandler->commentsChanged )
00801                         {
00802                                 $this->comments = $commenthandler->comments;
00803                                 $this->commentCount = $commenthandler->numberOfComments();
00804                                 $this->save( $commenthandler->lastComment, $commenthandler->lastCommenter );
00805                         }
00806                         
00807                         $docStats = "
00808                         <div class=\"documents-viewdoc-navigator-stats\">" . i18n("Rating: ##0##", array($dox_options["ratings"][$this->rating])) . "</div>
00809                         <div class=\"documents-viewdoc-navigator-stats\">" . i18n("Authors: ##0##", array($renderedAuthors)) . "</div>
00810                         <div class=\"documents-viewdoc-navigator-stats\">" . i18n("Document contains ##0## words and ##1## letters", array($wordcount, $lettercount)) . "</div>
00811                         <div class=\"documents-viewdoc-navigator-stats\">" . i18n("Categories: ##0##", array($categorylist)) . "</div>";
00812                         
00813                         $navigator = "
00814                         <table class=\"documents-viewdoc-navigator\">
00815                         <tr class=\"documents-viewdoc-navigator\">
00816                                 <td class=\"documents-viewdoc-navigator-previous\">$prevDocs</td>
00817                                 <td class=\"documents-viewdoc-navigator-stats\">$docStats</td>
00818                                 <td class=\"documents-viewdoc-navigator-next\">$nextDocs</td>
00819                         </tr>
00820                         </table>";
00821                         $renderedContent .= $navigator;
00822                         // Content
00823                         if( userAllows( $this->owner, $this->editLevel ) )
00824                                 $editLink = "<div class=\"documents-viewdoc-editlink\">" . drawCommand(i18n("Edit"), i18n("Edit the document"), globalIDtoURL("documents/edit/" . $this->id)) . "</div>";
00825                         $renderedContent .= $editLink . $subscriptions->renderSubscribeControl( "documents/view/" . $this->id, false ) . "
00826                                 <div class=\"documents-viewdoc-content\">" . parse_page_data($this->content) . "</div>
00827                                 " . $commenthandler->renderComments() . $commenthandler->renderCommentsAdder();
00828                         // Navigator again (same as above)
00829                         $renderedContent .= $navigator;
00830                 }
00831                 return "<div class=\"documents-breadcrumbs\">" . $trail->render() . "</div>"  . $renderedContent;
00832         }
00833 }
00834 
00836 class dox_category
00837 {
00838         var $id;                           
00839         var $parentToplevelCategory;       
00840         
00841         var $title;                        
00842         var $ids;                          
00843         
00845         var $datafile;                     
00846         var $documents;                    
00847         
00854         function dox_category( $id, $parentToplevelCategory )
00855         {
00856                 global $dox_categoryfolder;
00857                 $this->id = $id;
00858                 $this->parentID = &$parentToplevelCategory;
00859                 $this->datafile = "$dox_categoryfolder/" . $this->parentToplevelCategory . ".$id.php";
00860                 // Load the actual data
00861                 if( file_exists( $this->datafile ) )
00862                         include( $this->datafile );
00863                 
00864                 $this->title = $category["title"];
00865                 $this->ids = $category["ids"];
00866         }
00867         
00871         function save()
00872         {
00873                 if( file_exists( $this->datafile ) )
00874                         unlink( $this->datafile );
00875                 
00876                 $category["title"] = $this->title;
00877                 $category["ids"] = $this->ids;
00878                 
00879                 file_put_contents( $this->datafile, array_export( $category, "category" ) );
00880         }
00881         
00885         function render()
00886         {
00887                 // Cycle through all IDs and render them in block mode - fetch from global dox_alldocs
00888         }
00889 }
00890 
00892 class dox_topcategory
00893 {
00894         var $id;                           
00895         
00896         var $title;                        
00897         var $ids;                          
00898         
00899         var $categories;                   
00900         
00902         var $datafile;                     
00903         
00909         function dox_topcategory( $id )
00910         {
00911                 global $dox_categoryfolder;
00912                 
00913                 $this->datafile = "$dox_categoryfolder/$id.php";
00914                 
00915                 if( file_exists($this->datafile) )
00916                         include( $this->datafile );
00917                 
00918                 $this->title = $category["title"];
00919                 $this->ids = $category["ids"];
00920                 
00921                 // Load all contained categories
00922                 foreach($this->ids as $key => $value)
00923                         $this->categories[$value] = new dox_category( $value, $this->id );
00924         }
00925         
00929         function save()
00930         {
00931                 if( file_exists( $this->datafile ) )
00932                         unlink( $this->datafile );
00933                 
00934                 $category["title"] = $this->title;
00935                 $category["ids"] = $this->ids;
00936                 
00937                 file_put_contents( $this->datafile, array_export( $category, "category" ) );
00938         }
00939         
00945         function deleteCategory( $id )
00946         {
00947                 // Delete category file from disc
00948                 if( file_exists( $this->categories[$id]->datafile ) )
00949                         unlink( $this->categories[$id]->datafile );
00950                 // Delete category from array
00951                 unset( $this->categories[$id] );
00952                 unset( $this->ids[array_search($id, $this->ids)] );
00953                 // Save self
00954                 $this->save();
00955         }
00956         
00962         function newCategory( $title )
00963         {
00964                 $theEnd = endKey( $this->ids );
00965                 $this->ids[] = $theEnd + 1;
00966                 $this->categories[$theEnd + 1] = new dox_category( $theEnd + 1, &$this);
00967                 $this->categories[$theEnd + 1]->save();
00968                 $this->save();
00969         }
00970         
00974         function render()
00975         {
00976                 // Cycle through categories and show the title with a link and the count of IDs contained
00977                 foreach( $this->categories as $key => $category )
00978                         $renderedContent .= "<p class=\"documents-listing-category\"><a class=\"documents-listing-category\" href=\"" . globalIDtoURL( $category->globalID ) . "\">" . $category->title . " (" . count($category->ids) . ")</p>";
00979                 
00980                 if( $renderedContent != "" )
00981                         $renderedContent = "<p class=\"documents-listing-topcategory\">" . $this->title . "</p>" . $renderedContent;
00982                 
00983                 return $renderedContent;
00984         }
00985 }
00986 
00987 class dox_allcategories
00988 {
00989         var $topcategories;                
00990         
00991         function dox_allcategories()
00992         {
00993                 global $dox_categoryfolder;
00994                 $this->topcategories = array();
00995                 // Load all top level galleries from disc
00996                 $dir_handle = opendir( $dox_categoryfolder );
00997                 while( $file = readdir( $dir_handle ) )
00998                 {
00999                         if( substr($file, 0, 1) != "."  )
01000                         {
01001                                 $id = substr( $file, 0, -4 );
01002                                 // If there's a . in here, it means it's a category, not a top level category
01003                                 if( strpos( $id, "." ) === false )
01004                                         $this->topcategories[] = new dox_topcategory( $id );
01005                         }
01006                 }
01007                 closedir($dir_handle);
01008         }
01009         
01010         function render()
01011         {
01012                 global $dox_options;
01013                 
01014                 $renderedOptions = dox_renderListOptions();
01015                 
01016                 // render all the top categories
01017                 foreach( $this->topcategories as $key => $topcategory )
01018                         $renderedContent .= $topcategory->render();
01019                 
01020                 if( $renderedContent == "" )
01021                 {
01022                         $showThis = new dox_alldocs();
01023                         $renderedContent = $showThis->render();
01024                 }
01025                 else
01026                         $renderedContent .= $renderedOptions;
01027                 
01028                 return $renderedContent;
01029         }
01030 }
01031 
01033 class dox_alldocs
01034 {
01035         var $documents;                    
01036         var $sortby;                       
01037         var $thisRatingOnly = null;        
01038         
01040         var $datafile;                     
01041         
01045         function dox_alldocs()
01046         {
01047                 global $module_folder;
01048                 
01049                 $this->datafile = "$module_folder/documents/documents.php";
01050                 $this->documents = array();
01051                 if( file_exists( $this->datafile ) )
01052                         include( $this->datafile );
01053                 
01054                 $this->sortby = getUserInfo( currentUser(), "dox_sortby", "title" );
01055                 if( $_REQUEST["sortby"] != "" )
01056                         $this->sortby = $_REQUEST["sortby"];
01057         }
01058         
01071         function addDocument( $id, $title, $owner, $authors, $date, $modifydate, $rating, $blurb, $orphan )
01072         {
01073                 $this->documents[$id] = array( "id" => $id, "title" => $title, "owner" => $owner, "authors" => $authors, "date" => $date, "mdate" => $modifydate, "rating" => $rating, "blurb" => $blurb, "orphan" => $orphan );
01074                 $this->save();
01075         }
01076         
01082         function removeDocument( $id )
01083         {
01084                 unset( $this->documents[$id] );
01085                 $this->save();
01086         }
01087         
01091         function save()
01092         {
01093                 if( file_exists( $this->datafile ) )
01094                         unlink( $this->datafile );
01095                 
01096                 file_put_contents( $this->datafile, array_export( $this->documents, "this->documents" ) );
01097         }
01098         
01104         function render()
01105         {
01106                 global $dox_options, $dox_listingcolumns, $globalID, $subscriptions;
01107                 
01108                 $trail = new breadcrumbs( i18n("Documents"), globalIDtoURL("documents") );
01109                 
01110                 
01111                 // List all documents sorted by any of the things in the list, defaulting to title
01112                 $splitID = explode("/", $globalID);
01113                 $thisRatingOnly = $this->thisRatingOnly;
01114                 if( $splitID[1] == "rating" && array_key_exists( 2, $splitID ) )
01115                         $thisRatingOnly = $splitID[2];
01116                 
01117                 if( $thisRatingOnly != null )
01118                 {
01119                         $subscriptionControl = $subscriptions->renderSubscribeControl( "documents/rating/" . $thisRatingOnly, false );
01120                         $trail->addCrumb( i18n($dox_options["ratings"][$thisRatingOnly]), globalIDtoURL("documents/rating/" . $thisRatingOnly));
01121                         $shownItems = array();
01122                         foreach( $this->documents as $key => $value )
01123                         {
01124                                 if( $value["rating"] == $thisRatingOnly )
01125                                         $shownItems[] = $value;
01126                         }
01127                 }
01128                 else
01129                 {
01130                         $subscriptionControl = $subscriptions->renderSubscribeControl( "documents", false );
01131                         // Do the options thing - only if we're not listing a specific rating
01132                         $renderedOptions = dox_renderListOptions();
01133                         
01134                         // Get the documents to be shown (show only those the user requsts by way of filtering out those with unwanted ratings
01135                         $userShow = explode( ",", getUserInfo( currentUser(), "dox_showratings", implode( ",", array_keys($dox_options["ratings"] ) ) ) );
01136                         $shownItems = array();
01137                         foreach( $this->documents as $key => $value )
01138                         {
01139                                 if( in_array($value["rating"], $userShow) )
01140                                         $shownItems[] = $value;
01141                         }
01142                 }
01143                 
01144                 // Figure out what columns we're showing...
01145                 $userColumns = explode( ",", getUserInfo( currentUser(), "dox_showcolumns", implode( ",", array_values($dox_options["listingColumns"] ) ) ) );
01146                 // ...and render those columns' headers
01147                 $tableHeader = "
01148                 <tr class=\"documents-table-header\">";
01149                 foreach( $userColumns as $key => $value )
01150                 {
01151                         // Make sure we're going to sort in the correct order when you click on the header
01152                         $thisSort = $this->sortby == $value ? $value . "rev" : $value;
01153                         $tableHeader .= "<th class=\"documents-table documents-table-header-$value\"><a class=\"document-table-header\" href=\"" . thisPageURL(false, true, array("sortby" => "$thisSort")) . "\">" . $dox_listingcolumns[$value] . "</a></th>";
01154                 }
01155                 // Remember we need this column - otherwise the view command link will lack space
01156                 $tableHeader .= "
01157                         <th class=\"documents-table documents-table-header-right\">&nbsp;</th>
01158                 </tr>";
01159                 
01160                 // Sort data by requested sort order
01161                 usort( $shownItems, "dox_compare_" . $this->sortby );
01162                 
01163                 // Render each document
01164                 $renderedItems = "";
01165                 foreach( $shownItems as $key => $value )
01166                 {
01167                         $thisDoc = new dox_document( $value["id"] );
01168                         $renderedItems .= $thisDoc->renderBlock($userColumns);
01169                 }
01170                 
01171                 // Tell the user if we haven't got anything to show
01172                 if( $renderedItems == "" )
01173                         $renderedContent = renderInformationBox(i18n("No documents to show"), i18n("There are no documents fitting your request. There can be a number of causes for this. Either no documents exist in the system, or you have chosen a set of ratings all of which contain no documents. Please check your options below and try again."));
01174                 else
01175                         $renderedContent = "
01176                 <table class=\"documents-table\">$tableHeader$renderedItems
01177                 </table>";
01178                 
01179                 return "<div class=\"documents-breadcrumbs\">" . $trail->render() . "</div>" . $renderedContent . $renderedOptions;
01180         }
01181 }
01182 
01183 function dox_compare_title($x, $y) { return arrayColumnCompare($x, $y, "title"); }
01184 function dox_compare_titlerev($x, $y) { return arrayColumnCompare($x, $y, "title", true); }
01185 function dox_compare_date($x, $y) { return arrayColumnCompare($x, $y, "date"); }
01186 function dox_compare_daterev($x, $y) { return arrayColumnCompare($x, $y, "date", true); }
01187 function dox_compare_mdate($x, $y) { return arrayColumnCompare($x, $y, "mdate"); }
01188 function dox_compare_mdaterev($x, $y) { return arrayColumnCompare($x, $y, "mdate", true); }
01189 function dox_compare_owner($x, $y) { return arrayColumnCompare($x, $y, "owner"); }
01190 function dox_compare_ownerrev($x, $y) { return arrayColumnCompare($x, $y, "owner", true); }
01191 function dox_compare_authors($x, $y) { return arrayColumnCompare($x, $y, "authors"); }
01192 function dox_compare_authorsrev($x, $y) { return arrayColumnCompare($x, $y, "authors", true); }
01193 function dox_compare_rating($x, $y) { return arrayColumnCompare($x, $y, "rating"); }
01194 function dox_compare_ratingrev($x, $y) { return arrayColumnCompare($x, $y, "rating", true); }
01195 
01196 function parse_documents( $page_data )
01197 {
01198         global $globalID, $page_id, $dox_options, $meta_headers, $module_folder;
01199         
01200         $loopcontrol = 0;
01201         $moduleCommandName = "document";
01202         while( $parameters = spotModuleCommand( $page_data, $moduleCommandName, &$loopcontrol ) )
01203         {
01204                 if( $parameters == " " )
01205                         $parameters = "";
01206                 
01207                 $showThis = new dox_document( $parameters );
01208                 
01209                 $replaceData = $showThis->render();
01210                 $rendered = true;
01211                 
01212                 $page_data = str_replace( "\\$moduleCommandName($parameters)", $replaceData, $page_data );
01213         }
01214         
01215         $loopcontrol = 0;
01216         $moduleCommandName = "documentrating";
01217         while( ( $parameters = spotModuleCommand( $page_data, $moduleCommandName, &$loopcontrol ) ) !== false )
01218         {
01219                 if( $parameters == " " )
01220                         $parameters = "";
01221                 
01222                 $showThis = new dox_alldocs();
01223                 $showThis->thisRatingOnly = $parameters == "" ? null : $parameters;
01224                 
01225                 $replaceData = $showThis->render();
01226                 $rendered = true;
01227                 
01228                 $page_data = str_replace( "\\$moduleCommandName($parameters)", $replaceData, $page_data );
01229         }
01230         
01231         $loopcontrol = 0;
01232         $moduleCommandName = "documentlink";
01233         while( $parameters = spotModuleCommand( $page_data, $moduleCommandName, &$loopcontrol ) )
01234         {
01235                 if( $parameters == " " )
01236                         $parameters = "";
01237                 
01238                 $showThis = new dox_document( $parameters );
01239                 
01240                 $replaceData = "<a href=\"" . globalIDtoURL("documents/view/" . $showThis->id) . "\">" . $showThis->title . "</a>";
01241                 $rendered = true;
01242                 
01243                 $page_data = str_replace( "\\$moduleCommandName($parameters)", $replaceData, $page_data );
01244         }
01245         
01246         $loopcontrol = 0;
01247         $moduleCommandName = "documents";
01248         while( $parameters = spotModuleCommand( $page_data, $moduleCommandName, &$loopcontrol ) )
01249         {
01250                 if( $parameters == " " )
01251                         $parameters = "";
01252                 
01253                 if( strlen($parameters) > 0 )
01254                         $splitID = explode("/", $parameters);
01255                 else
01256                         $splitID = explode("/", $globalID);
01257                 
01258                 $replaceData = ""; // Let's initialize to an empty string...
01259                 if( $page_id == $dox_options["page_id"] )
01260                 {
01261                         switch( $splitID[1] )
01262                         {
01263                                 case "view":
01264                                 case "edit":
01265                                         if( array_key_exists( 2, $splitID ) )
01266                                         {
01267                                                 // Show the document if we've got an ID
01268                                                 $showThis = new dox_document( $splitID[2] );
01269                                                 if( $splitID[1] == "edit" && $showThis->userCanEdit() )
01270                                                         $showThis->edit = true;
01271                                         }
01272                                         else
01273                                         {
01274                                                 // List all top level categories if we've not got an ID to show
01275                                                 $showThis = new dox_allcategories();
01276                                         }
01277                                         break;
01278                                 case "category":
01279                                         if( array_key_exists( 2, $splitID ) )
01280                                         {
01281                                                 // Get the top level gallery
01282                                                 $theTopcategory = new dox_topcategory( $splitID[2] );
01283                                                 if( array_key_exists( 3, $splitID ) )
01284                                                 {
01285                                                         // List documents in this category if we've got a category...
01286                                                         $showThis = new dox_category( $splitID[3], $theTopcategory->id );
01287                                                 }
01288                                                 else
01289                                                 {
01290                                                         // Otherwise just show the top level category 
01291                                                         $showThis = &$theTopcategory;
01292                                                 }
01293                                         }
01294                                         else
01295                                         {
01296                                                 // List all top level categories if we've not got an ID to show
01297                                                 $showThis = new dox_allcategories();
01298                                         }
01299                                         break;
01300                                 case "rating":
01301                                         if( array_key_exists( 3, $splitID ) )
01302                                         {
01303                                                 // List all documents with this rating
01304                                         }
01305                                         else
01306                                         {
01307                                                 // List all top level categories if we've not got an ID to show
01308                                                 $showThis = new dox_allcategories();
01309                                         }
01310                                         break;
01311                                 case "listall":
01312                                         // List all documents
01313                                         $showThis = new dox_alldocs();
01314                                         break;
01315                                 case "toplevel":
01316                                 default:
01317                                         // List all toplevel categories
01318                                         $showThis = new dox_allcategories();
01319                         }
01320                         $replaceData = $showThis->render();
01321                         $rendered = true;
01322                 }
01323                 
01324                 $page_data = str_replace( "\\$moduleCommandName($parameters)", $replaceData, $page_data );
01325         }
01326         
01327         if( $rendered )
01328                 $meta_headers .= "
01329         <link rel=\"StyleSheet\" href=\"" . siteURL(true) . "$module_folder/documents/documents.css\" type=\"text/css\" />";
01330         
01331         return $page_data;
01332 }
01333 
01334 function profilemodule_documents()
01335 {
01336         global $tabwidget, $meta_headers, $module_folder, $viewUser, $globalID, $permissionlevels_array, $dox_options;
01337         $splitID = explode( "/", $globalID );
01338         $meta_headers .= "
01339         <link rel=\"StyleSheet\" href=\"" . siteURL(true) . "$module_folder/documents/documents.css\" type=\"text/css\" />";
01340         
01341         if( currentUser() == $viewUser || isAllowed("global_user_edit") )
01342         {
01343                 $tabwidget->addCommand( i18n("New"), i18n("Create a new document"), globalIDtoURL("user/$viewUser/documents/new") );
01344                 $tabwidget->addCommand( i18n("Options"), i18n("Change the document options"), globalIDtoURL("user/$viewUser/documents/options") );
01345                 $tabwidget->addCommand( i18n("View"), i18n("View ##0##'s documents", array(getUserInfo($viewUser, "name"))), globalIDtoURL("user/$viewUser/documents") );
01346         }
01347         
01348         switch( $splitID[3] )
01349         {
01350                 // User's personal options, defaults for new documents - user/username/documents/options
01351                 case "options":
01352                         if( !userAllows( $theDocument->owner, $theDocument->editLevel ) )
01353                                 header("Location: " . globalIDtoURL("user/$viewUser/documents") );
01354                         
01355                         $panel = new optionsPanel("");
01356                         
01357                         $values["viewLevel"] = $_POST["viewLevel"] == "" ? getUserInfo($viewUser, "dox_viewLevel", $dox_options["viewLevel"]) : $_POST["viewLevel"];
01358                         $values["commentLevel"] = $_POST["commentLevel"] == "" ? getUserInfo($viewUser, "dox_commentLevel", $dox_options["commentLevel"]) : $_POST["commentLevel"];
01359                         $values["editLevel"] = $_POST["editLevel"] == "" ? getUserInfo($viewUser, "dox_editLevel", $dox_options["editLevel"]) : $_POST["editLevel"];
01360                         
01361                         $panel->addOption(
01362                                 i18n("Viewing allowance level"),
01363                                 i18n("Who except ##0## is allowed to view documents owned by ##0##?", array($viewUser)),
01364                                 $values["viewLevel"],
01365                                 "viewLevel",
01366                                 "select",
01367                                 $permissionlevels_array);
01368                         $panel->addOption(
01369                                 i18n("Commenting allowance level"),
01370                                 i18n("Who except ##0## is allowed to view documents owned by ##0##?", array($viewUser)),
01371                                 $values["commentLevel"],
01372                                 "commentLevel",
01373                                 "select",
01374                                 $permissionlevels_array);
01375                         $panel->addOption(
01376                                 i18n("Editing allowance level"),
01377                                 i18n("Who except ##0## is allowed to view documents owned by ##0##?", array($viewUser)),
01378                                 $values["editLevel"],
01379                                 "editLevel",
01380                                 "select",
01381                                 $permissionlevels_array);
01382                         
01383                         if( $_POST["saveOptions"] )
01384                         {
01385                                 saveUserInfo($viewUser, "dox_viewLevel", $values["viewLevel"]);
01386                                 saveUserInfo($viewUser, "dox_commentLevel", $values["commentLevel"]);
01387                                 saveUserInfo($viewUser, "dox_editLevel", $values["editLevel"]);
01388                         }
01389                         
01390                         $renderedContent = $panel->render();
01391                         break;
01392                 // Let user delete their documents - user/username/documents/delete/id
01393                 case "delete":
01394                         if( array_key_exists( 4, $splitID ) )
01395                         {
01396                                 $theDocument = new dox_document( $splitID[4] );
01397                                 if( !userAllows( $theDocument->owner, $theDocument->editLevel ) )
01398                                         header("Location: " . globalIDtoURL("user/$viewUser/documents") );
01399                                 else
01400                                 {
01401                                         if( $_REQUEST["confirmDelete"] == "true" )
01402                                         {
01403                                                 $theDocument->delete();
01404                                                 header("Location: " . globalIDtoURL("user/$viewUser/documents") );
01405                                         }
01406                                         else
01407                                                 $renderedContent = renderInformationBox(
01408                                                         i18n("Delete document?"),
01409                                                         i18n("Are you sure you wish to delete the document ##0##?", array("&quot;" . $theDocument->title . "&quot;")) .
01410                                                                 "<div class=\"wikicenteralign\">" .
01411                                                                 drawCommand(i18n("Confirm delete"), i18n("Comfirm deletion of ##0##", array($theDocument->title)), globalIDtoURL("user/$viewUser/documents/delete/" . $theDocument->id, array("confirmDelete" => "true"))) . " " .
01412                                                                 drawCommand(i18n("Abort delete"), i18n("Abort the deletion process"), globalIDtoURL("user/$viewUser/documents")) . "</div>",
01413                                                         false);
01414                                 }
01415                         }
01416                         else
01417                                 header("Location: " . globalIDtoURL("user/$viewUser/documents") );
01418                         break;
01419                 // Let user publish and unpublish their documents - user/username/documents/togglepublish/id
01420                 case "togglepublish":
01421                         if( array_key_exists( 4, $splitID ) )
01422                         {
01423                                 $theDocument = new dox_document( $splitID[4] );
01424                                 if( userAllows( $theDocument->owner, $theDocument->editLevel ) )
01425                                 {
01426                                         $theDocument->published = !$theDocument->published;
01427                                         $theDocument->save();
01428                                 }
01429                         }
01430                         header("Location: " . globalIDtoURL("user/$viewUser/documents") );
01431                         
01432                         break;
01433                 // Let user edit their documents - user/username/documents/edit/id
01434                 case "edit":
01435                         if( array_key_exists( 4, $splitID ) )
01436                         {
01437                                 if( !userAllows( $theDocument->owner, $theDocument->editLevel ) )
01438                                         header("Location: " . globalIDtoURL("user/$viewUser/documents") );
01439                                 else
01440                                 {
01441                                         $theDocument = new dox_document( $splitID[4] );
01442                                         $theDocument->edit = true;
01443                                         $renderedContent = $theDocument->renderEditor();
01444                                 }
01445                         }
01446                         else
01447                                 header("Location: " . globalIDtoURL("user/$viewUser/documents") );
01448                         break;
01449                 // Let user create new documents - user/username/documents/new
01450                 case "new":
01451                         if( !userAllows( $theDocument->owner, $theDocument->editLevel ) )
01452                                 header("Location: " . globalIDtoURL("user/$viewUser/documents") );
01453                         
01454                         $panel = new optionsPanel("");
01455                         $panel->saveTitle = i18n("Create document");
01456                         $panel->revertTitle = i18n("Reset to defaults");
01457                         $panel->showHeader = false;
01458                         
01459                         $values["title"] = $_POST["title"] == "" ? i18n("New title") : stripslashes($_POST["title"]);
01460                         $values["blurb"] = $_POST["blurb"] == "" ? i18n("A description of the document!") : stripslashes($_POST["blurb"]);
01461                         $values["rating"] = $_POST["rating"] == "" ? $dox_options["rating"] : $_POST["rating"];
01462                         $values["viewLevel"] = $_POST["viewLevel"] == "" ? getUserInfo($viewUser, "dox_viewLevel", $dox_options["viewLevel"]) : $_POST["viewLevel"];
01463                         $values["commentLevel"] = $_POST["commentLevel"] == "" ? getUserInfo($viewUser, "dox_commentLevel", $dox_options["commentLevel"]) : $_POST["commentLevel"];
01464                         $values["editLevel"] = $_POST["editLevel"] == "" ? getUserInfo($viewUser, "dox_editLevel", $dox_options["editLevel"]) : $_POST["editLevel"];
01465                         $values["content"] = $_POST["content"] == "" ? i18n("Write the contents of your document in this field. Formatting help can be found below.") : stripslashes($_POST["content"]);
01466                         
01467                         $panel->addHeader(
01468                                 i18n("Create a new document"),
01469                                 "first");
01470                         $panel->addOption(
01471                                 i18n("Title"),
01472                                 i18n("Title of the new document"),
01473                                 $values["title"],
01474                                 "title",
01475                                 "text");
01476                         $panel->addOption(
01477                                 i18n("Blurb"),
01478                                 i18n("A short description of the document"),
01479                                 $values["blurb"],
01480                                 "blurb",
01481                                 "text");
01482                         $panel->addOption(
01483                                 i18n("Rating"),
01484                                 i18n("What rating does this document fall under?"),
01485                                 $values["rating"],
01486                                 "rating",
01487                                 "select",
01488                                 $dox_options["ratings"]);
01489                         $panel->addOption(
01490                                 i18n("Viewing allowance level"),
01491                                 i18n("Who except ##0## is allowed to view documents owned by ##0##?", array($viewUser)),
01492                                 $values["viewLevel"],
01493                                 "viewLevel",
01494                                 "select",
01495                                 $permissionlevels_array);
01496                         $panel->addOption(
01497                                 i18n("Commenting allowance level"),
01498                                 i18n("Who except ##0## is allowed to view documents owned by ##0##?", array($viewUser)),
01499                                 $values["commentLevel"],
01500                                 "commentLevel",
01501                                 "select",
01502                                 $permissionlevels_array);
01503                         $panel->addOption(
01504                                 i18n("Editing allowance level"),
01505                                 i18n("Who except ##0## is allowed to view documents owned by ##0##?", array($viewUser)),
01506                                 $values["editLevel"],
01507                                 "editLevel",
01508                                 "select",
01509                                 $permissionlevels_array);
01510                         $panel->addOption(
01511                                 i18n("Document contents"),
01512                                 "",
01513                                 $values["content"],
01514                                 "content",
01515                                 "pagedata");
01516                         
01517                         if( $_POST["saveOptions"] )
01518                         {
01519                                 $document["title"] = $values["title"];
01520                                 $document["modifydate"] = $document["createdate"] = time();
01521                                 $document["blurb"] = $values["blurb"];
01522                                 $document["published"] = false;
01523                                 $document["backwardrel"] = array();
01524                                 $document["forwardrel"] = array();
01525                                 $document["owner"] = $viewUser;
01526                                 $document["viewLevel"] = $values["viewLevel"];
01527                                 $document["commentLevel"] = $values["commentLevel"];
01528                                 $document["comments"] = array();
01529                                 $document["commentCount"] = 0;
01530                                 $document["editLevel"] = $values["editLevel"];
01531                                 $document["authors"] = array($viewUser);
01532                                 $document["categories"] = array();
01533                                 $document["rating"] = $values["rating"];
01534                                 
01535                                 $theDocument = new dox_document( 0, $document );
01536                                 
01537                                 $theDocument->saveContent( $values["content"] );
01538                                 
01539                                 header("Location: " . globalIDtoURL( "user/$viewUser/documents") );
01540                         }
01541                         else
01542                                 $renderedContent = $panel->render();
01543                         
01544                         break;
01545                 // List user's documents (owner) - user/username/documents
01546                 default:
01547                         $theDocuments = new dox_alldocs();
01548                         $listed = false;
01549                         $renderedContent = "
01550                         <table class=\"documents-profilelist\">";
01551                         foreach( $theDocuments->documents as $key => $value )
01552                         {
01553                                 if( ( is_array($value["authors"]) && in_array( $viewUser, $value["authors"] ) ) || $viewUser == $value["owner"] )
01554                                 {
01555                                         $listed = true;
01556                                         $theDocument = new dox_document( $value["id"] );
01557                                         
01558                                         if( userAllows( $theDocument->owner, $theDocument->editLevel ) )
01559                                         {
01560                                                 $publishTitle = $theDocument->published ? i18n("Unpublish") : i18n("Publish");
01561                                                 $editCell = "
01562                                                 " . drawCommand( i18n("Delete"), i18n("Delete the document"), globalIDtoURL( "user/$viewUser/documents/delete/" . $theDocument->id ) ) . "
01563                                                 " . drawCommand( i18n("Edit"), i18n("Edit the document"), globalIDtoURL( "user/$viewUser/documents/edit/" . $theDocument->id ) ) . "
01564                                                 " . drawCommand( $publishTitle, i18n("Toggle the published status of the document"), globalIDtoURL( "user/$viewUser/documents/togglepublish/" . $theDocument->id ) ) . "";
01565                                         }
01566                                         
01567                                         $renderedContent .= "
01568                                         <tr class=\"documents-profilelist\">
01569                                                 <td class=\"documents-profilelist-info\">
01570                                                 " . $value["title"] . "<small class=\"comment\">" . $value["blurb"] . "</small>
01571                                                 </td>
01572                                                 <td class=\"documents-profilelist-commands\">$editCell
01573                                                 " . drawCommand( i18n("View") . "&raquo", i18n("View the document"), globalIDtoURL( "documents/view/" . $theDocument->id ) ) . "
01574                                                 </td>
01575                                         </tr>";
01576                                 }
01577                         }
01578                         $renderedContent .= "
01579                         </table>";
01580                         
01581                         if( !$listed )
01582                                 $renderedContent = renderInformationBox( i18n("No documents"), i18n( "##0## has not yet created any documents.", array( getUserInfo( $viewUser, "name" ) ) ) );
01583         }
01584         return "<form action=\"" . globalIDtoURL($globalID) . "\" method=\"POST\">" . $renderedContent . "</form>";
01585 }
01586 
01587 function modulesetup_documents()
01588 {
01589         global $pagectl, $setup_folder, $page_folder, $recent_file, $menu_folder, $theModuleSection, $theModuleSubsection, $theModuleAction, $dox_options, $default_language, $permissionlevels_array;
01590         
01591         $doxSetup = new TabWidget();
01592         $doxSetup->tabbar->addTab(i18n("All Documents"), globalIDtoURL("setup/modulesetup/documents"));
01593         $doxSetup->tabbar->addTab(i18n("Document Ratings"), globalIDtoURL("setup/modulesetup/documents/ratings"));
01594         $doxSetup->tabbar->addTab(i18n("Document Categories"), globalIDtoURL("setup/modulesetup/documents/categories"));
01595         $doxSetup->tabbar->addTab(i18n("Options"), globalIDtoURL("setup/modulesetup/documents/options"));
01596         
01597         switch( $theModuleSection )
01598         {
01599         case "options":
01600                 $doxSetup->tabbar->setCurrent(i18n("Options"));
01601                 if( $theModuleAction == "create_documents_page" )
01602                 {
01603                         // Create the page to save the forum to!
01604                         $edit_page["id"] = $pagectl->getFreePageID($page_folder, $pagectl);
01605                         $edit_page["title"] = $dox_options["title"];
01606                         $edit_page["menu"] = $dox_options["menu_id"];
01607                         $edit_page["language"] = $default_language;
01608                         $edit_page["content"] = "\\\\documents()";
01609                         $edit_page["author"] = getUserInfo(currentUser(), "name");
01610                         $edit_page["email"] = getUserInfo(currentUser(), "email");
01611                         
01612                         unlink_multiple( "$page_folder/{$edit_page['id']}.*" );
01613                         
01614                         if ($pagectl->savePageData($page_folder, $edit_page["id"], $edit_page["language"], $edit_page["author"], $edit_page["email"], $dox_options["menu_id"], $edit_page["title"], $edit_page["content"])) {
01615                                 update_getpage_id($page_folder, $setup_folder, $pagectl);
01616                                 rotate_recent($edit_page["id"], $edit_page["title"], $edit_page["language"], date("j/n/y"), $recent_file);
01617                                 
01618                                 $dox_options["page_id"] = $edit_page["id"];
01619                                 dox_saveOptions();
01620                                 
01621                                 header("Location: " . globalIDtoURL("setup/modulesetup/documents/options"));
01622                         } else {
01623                                 $error_description = parse_page_data(i18n("The documents page could not be saved!"));
01624                         }
01625                 }
01626                 if( $_POST["saveOptions"] && $_POST["dox"]["page_id"] != 12 && ( $dox_options["page_id"] != $_POST["dox"]["page_id"] || $dox_options["menu_id"] != $_POST["dox"]["menu_id"] || $dox_options["title"] != $_POST["dox"]["title"] ) )
01627                 {
01628                         $thePage = $pagectl->fetchPageData($_POST["page_id"]);
01629                         unlink_multiple( "$page_folder/{$dox_options['page_id']}.*" );
01630                         if ($pagectl->savePageData($page_folder, $_POST["dox"]["page_id"], $thePage["language"], $thePage["author"], $thePage["email"], $_POST["dox"]["menu_id"], $_POST["dox"]["title"], "\\\\documents()"))
01631                         {
01632                                 update_getpage_id($page_folder, $setup_folder, $pagectl);
01633                                 rotate_recent($dox_options["page_id"], $dox_options["title"], $thePage["language"], date("j/n/y"), $recent_file);
01634                         }
01635                 }
01636                 $panel = new optionsPanel("dox");
01637                 $panel->showHeader = false;
01638                 
01639                 $values["page_id"] = $_POST["dox"]["page_id"] ? $_POST["dox"]["page_id"] : $dox_options["page_id"];
01640                 $values["title"] = $_POST["dox"]["title"] ? stripslashes($_POST["dox"]["title"]) : $dox_options["title"];
01641                 $values["menu_id"] = $_POST["dox"]["menu_id"] ? $_POST["dox"]["menu_id"] : $dox_options["menu_id"];
01642                 $values["rating"] = $_POST["dox"]["rating"] ? $_POST["dox"]["rating"] : $dox_options["rating"];
01643                 $values["viewLevel"] = $_POST["dox"]["viewLevel"] ? $_POST["dox"]["viewLevel"] : $dox_options["viewLevel"];
01644                 $values["commentLevel"] = $_POST["dox"]["commentLevel"] ? $_POST["dox"]["commentLevel"] : $dox_options["commentLevel"];
01645                 $values["editLevel"] = $_POST["dox"]["editLevel"] ? $_POST["dox"]["editLevel"] : $dox_options["editLevel"];
01646                 
01647                 $panel->addHeader( i18n("Documents page"), "thepage" );
01648                 
01649                 $pagelist = $pagectl->fetchPageList($page_folder);
01650                 $temp_pagelist[12] = i18n("Please select a page...");
01651                 foreach( $pagelist as $key => $value )
01652                 {
01653                         $temp_pagelist[$key] = $value["title"][0];
01654                 }
01655                 $panel->addOption(
01656                         i18n("Documents page"),
01657                         i18n("This is the page that will be used to show the documents on. If you want to create a new page to put the information into, ##0##simply click here##1## and this will be done for you.", array("<a href=\"" . globalIDtoURL("setup/modulesetup/documents/options/na/create_documents_page") . "\">", "</a>")),
01658                         $values["page_id"],
01659                         "page_id",
01660                         "select",
01661                         $temp_pagelist
01662                 );
01663                 
01664                 $panel->addOption(
01665                         i18n("Title"),
01666                         i18n("The title of the documents page"),
01667                         $values["title"],
01668                         "title",
01669                         "text"
01670                 );
01671                 
01672                 $menulist = $pagectl->fetchMenuMenuList($menu_folder);
01673                 foreach( $menulist as $key => $value )
01674                 {
01675                         $temp_menulist[$value["id"]] = $value["title"][0];
01676                 }
01677                 $panel->addOption(
01678                         i18n("Documents menu"),
01679                         i18n("This is the menu that will be shown on the document page"),
01680                         $values["menu_id"],
01681                         "menu_id",
01682                         "select",
01683                         $temp_menulist
01684                 );
01685                 
01686                 $panel->addHeader( i18n("Defaults for new users"), "defaults" );
01687                 
01688                 $panel->addOption(
01689                         i18n("Rating"),
01690                         i18n("What rating do new documents fall under by default?"),
01691                         $values["rating"],
01692                         "rating",
01693                         "select",
01694                         $dox_options["ratings"]);
01695                 $panel->addOption(
01696                         i18n("Viewing allowance level"),
01697                         i18n("Who except the user itself is allowed to view documents owned by them?"),
01698                         $values["viewLevel"],
01699                         "viewLevel",
01700                         "select",
01701                         $permissionlevels_array);
01702                 $panel->addOption(
01703                         i18n("Commenting allowance level"),
01704                         i18n("Who except the user itself is allowed to comment on documents owned by them?"),
01705                         $values["commentLevel"],
01706                         "commentLevel",
01707                         "select",
01708                         $permissionlevels_array);
01709                 $panel->addOption(
01710                         i18n("Editing allowance level"),
01711                         i18n("Who except the user itself is allowed to view documents owned by them?"),
01712                         $values["editLevel"],
01713                         "editLevel",
01714                         "select",
01715                         $permissionlevels_array);
01716                 
01717                 if( $_POST["saveOptions"] )
01718                 {
01719                         $dox_options["page_id"] = $_POST["dox"]["page_id"];
01720                         $dox_options["menu_id"] = $_POST["dox"]["menu_id"];
01721                         $dox_options["title"] = $_POST["dox"]["title"];
01722                         
01723                         $dox_options["rating"] = $_POST["dox"]["rating"];
01724                         $dox_options["viewLevel"] = $_POST["dox"]["viewLevel"];
01725                         $dox_options["commentLevel"] = $_POST["dox"]["commentLevel"];
01726                         $dox_options["editLevel"] = $_POST["dox"]["editLevel"];
01727                         
01728                         dox_saveOptions();
01729                 }
01730                 
01731                 $doxSetup->contents = "<form action=\"" . thisPageURL() . "\" method=\"POST\">" . $panel->render() . "</form>";
01732                 
01733                 break;
01734         case "categories":
01735                 $doxSetup->tabbar->setCurrent(i18n("Document Categories"));
01736                 $doxSetup->contents = renderInformationBox(i18n("Incomplete"), i18n("This is non-completed functionality - sorry for the inconvenience!"));
01737                 // Create top level category
01738                 // Edit title of top level category
01739                 // Delete top level category
01740                 // Create category inside top level category
01741                 // Edit title inside top level category
01742                 // Delete top level category
01743                 break;
01744         case "ratings":
01745                 $doxSetup->tabbar->setCurrent(i18n("Document Ratings"));
01746                 $doxSetup->addCommand(i18n("New"), i18n("Create new rating"), globalIDtoURL("setup/modulesetup/documents/ratings/new"));
01747                 // Ratings
01748                 switch( $theModuleSubsection )
01749                 {
01750                 case "new":
01751                         $panel = new optionsPanel("");
01752                         $panel->saveTitle = i18n("Save new title");
01753                         $panel->showHeader = false;
01754                         
01755                         $values["title"] = $_POST["title"] ? stripslashes($_POST["title"]) : $dox_options["ratings"][$theModuleAction];
01756                         
01757                         $panel->addOption( i18n("New title"), i18n("Enter the new rating's title here"), $values["title"], "title", "text");
01758                         
01759                         if( $_POST["saveOptions"] && $values["title"] != "")
01760                         {
01761                                 $dox_options["ratings"][] = $values["title"];
01762                                 dox_saveOptions();
01763                                 header("Location: " . globalIDtoURL("setup/modulesetup/documents/ratings"));
01764                         }
01765                         if( $values["title"] == "" )
01766                                 $panel->options["title"]["error"] = i18n("You cannot have a rating without a title!");
01767                         
01768                         $renderedContent = renderInformationBox(i18n("Create new rating"), $panel->render(), false);
01769                         break;
01770                 case "edit":
01771                         $panel = new optionsPanel("");
01772                         $panel->saveTitle = i18n("Save new title");
01773                         $panel->showHeader = false;
01774                         
01775                         $values["title"] = $_POST["title"] ? stripslashes($_POST["title"]) : $dox_options["ratings"][$theModuleAction];
01776                         
01777                         $panel->addOption( i18n("New title"), i18n("Enter the rating's new title here"), $values["title"], "title", "text");
01778                         
01779                         if( $_POST["saveOptions"] && $values["title"] != "" )
01780                         {
01781                                 $dox_options["ratings"][$theModuleAction] = $values["title"];
01782                                 dox_saveOptions();
01783                                 header("Location: " . globalIDtoURL("setup/modulesetup/documents/ratings"));
01784                         }
01785                         
01786                         $renderedContent = renderInformationBox(i18n("Edit rating title"), $panel->render(), false);
01787                         break;
01788                 case "delete":
01789                         if( $_REQUEST["confirmDelete"] == "true" )
01790                         {
01791                                 unset( $dox_options["ratings"][$theModuleAction] );
01792                                 dox_saveOptions();
01793                                 header("Location: " . globalIDtoURL("setup/modulesetup/documents/ratings"));
01794                         }
01795                         $renderedContent = renderInformationBox(i18n("Delete this rating?"),
01796                                 parse_page_data(i18n("Are you sure you wish to delete the rating with the title ##0##?", array("&quot;" . $dox_options["ratings"][$theModuleAction] . "&quot;"))) .
01797                                 "<div class=\"wikicenteralign\">" .
01798                                         drawCommand( i18n("Confirm delete"), i18n("Confirm deletion of ##0##", array($dox_options["ratings"][$theModuleAction])), globalIDtoURL( "setup/modulesetup/documents/ratings/delete/$theModuleAction", array("confirmDelete" => "true") ) ) . " " .
01799                                         drawCommand( i18n("Abort delete"), i18n("Abort the deletion process"), globalIDtoURL("setup/modulesetup/documents/ratings") ) .
01800                                 "</div>",
01801                                 false);
01802                         break;
01803                 default:
01804                         $allDocs = new dox_alldocs();
01805                         foreach( $allDocs->documents as $key => $value )
01806                                 $ratingCount[$value["rating"]]++;
01807                         
01808                         $renderedContent = "
01809                         <table class=\"setup\">";
01810                         foreach( $dox_options["ratings"] as $key => $value )
01811                         {
01812                                 if( $ratingCount[$key] == 0 )
01813                                 {
01814                                         $deleteThis = drawCommand( i18n("Delete"), i18n("Delete this rating"), globalIDtoURL("setup/modulesetup/documents/ratings/delete/$key") );
01815                                         $cantDelete = "<small class=\"comment\">" . i18n("Deletable: 0 documents are rated with this rating") . "</small>";
01816                                 }
01817                                 else
01818                                 {
01819                                         $deleteThis = "(" . i18n("Delete") . ")";
01820                                         $cantDelete = "<small class=\"comment\">" . i18n("Cannot delete: ##0## documents are rated with this rating", array($ratingCount[$key])) . "</small>";
01821                                 }
01822                                 
01823                                 $renderedContent .= "
01824                                 <tr class=\"setup\">
01825                                         <td class=\"setup\">
01826                                                 $value $cantDelete
01827                                         </td>
01828                                         <td class=\"setup\">
01829                                                 <div class=\"wikirightalign\">
01830                                                         " . $deleteThis . "
01831                                                         " . drawCommand( i18n("Edit"), i18n("Edit this rating"), globalIDtoURL("setup/modulesetup/documents/ratings/edit/$key") ) . "
01832                                                 </div>
01833                                         </td>
01834                                 </tr>";
01835                         }
01836                         $renderedContent .= "
01837                         </table>";
01838                         break;
01839                 }
01840                 $doxSetup->contents = "<form action=\"" . thisPageURL() . "\" method=\"POST\">" . $renderedContent . "</form>";
01841                 break;
01842         default:
01843                 $doxSetup->tabbar->setCurrent(i18n("All Documents"));
01844                 // List all documents
01845                 $allDocs = new dox_alldocs();
01846                 
01847                 $listed = false;
01848                 $renderedContent = "
01849                 <table class=\"documents-profilelist\">";
01850                 foreach( $allDocs->documents as $key => $value )
01851                 {
01852                         $listed = true;
01853                         $theDocument = new dox_document( $value["id"] );
01854                         
01855                         if( userAllows( $theDocument->owner, $theDocument->editLevel ) )
01856                         {
01857                                 $publishTitle = $theDocument->published ? i18n("Unpublish") : i18n("Publish");
01858                                 $editCell = "
01859                                 " . drawCommand( i18n("Delete"), i18n("Delete the document"), globalIDtoURL( "user/$viewUser/documents/delete/" . $theDocument->id ) ) . "
01860                                 " . drawCommand( i18n("Edit"), i18n("Edit the document"), globalIDtoURL( "user/$viewUser/documents/edit/" . $theDocument->id ) ) . "
01861                                 " . drawCommand( $publishTitle, i18n("Toggle the published status of the document"), globalIDtoURL( "user/$viewUser/documents/togglepublish/" . $theDocument->id ) ) . "";
01862                         }
01863                         
01864                         $renderedContent .= "
01865                         <tr class=\"documents-profilelist\">
01866                                 <td class=\"documents-profilelist-info\">
01867                                 " . $value["title"] . "<small class=\"comment\">" . $value["blurb"] . "</small>
01868                                 </td>
01869                                 <td class=\"documents-profilelist-commands\">$editCell
01870                                 " . drawCommand( i18n("View") . "&raquo", i18n("View the document"), globalIDtoURL( "documents/view/" . $theDocument->id ) ) . "
01871                                 </td>
01872                         </tr>";
01873                 }
01874                 $renderedContent .= "
01875                 </table>";
01876                 
01877                 if( !$listed )
01878                         $renderedContent = renderInformationBox( i18n("No documents"), i18n( "There has not yet been created any documents. If you wish to create one, please visit your profile's Documents panel and click on the New command link, ##0##or simply click here to create a new document##1##", array("<a href=\"" . globalIDtoURL("user/" . currentUser() . "/documents/new") . "\">", "</a>") ) );
01879                 
01880                 $doxSetup->contents = $renderedContent;
01881         }
01882         return $doxSetup->renderTabwidget();
01883 }
01884 
01885 function dox_saveOptions()
01886 {
01887         global $dox_options, $dox_optionfile;
01888         if( file_exists( $dox_optionfile ) )
01889                 unlink( $dox_optionfile );
01890         
01891         file_put_contents( $dox_optionfile, array_export( $dox_options, "dox_options" ) );
01892 }
01893 
01899 function dox_nextID()
01900 {
01901         global $dox_options;
01902         $dox_options["nextID"]++;
01903         dox_saveOptions();
01904         return $dox_options["nextID"];
01905 }
01906 
01907 function dox_renderListOptions()
01908 {
01909         global $dox_options, $dox_listingcolumns;
01910         if( $_POST["saveOptions"] )
01911         {
01912                 $userShow = array();
01913                 foreach( $_POST["showThis"] as $key => $value )
01914                         $userShow[] = $key;
01915                 saveUserInfo( currentUser(), "dox_showratings", implode( ",", $userShow ) );
01916                 
01917                 $userColumns = array();
01918                 foreach( $_POST["showColumns"] as $key => $value )
01919                         $userColumns[] = $key;
01920                 saveUserInfo( currentUser(), "dox_showcolumns", implode( ",", $userColumns ) );
01921         }
01922         else
01923         {
01924                 $userShow = explode( ",", getUserInfo( currentUser(), "dox_showratings", implode( ",", array_keys($dox_options["ratings"] ) ) ) );
01925                 $userColumns = explode( ",", getUserInfo( currentUser(), "dox_showcolumns", implode( ",", array_values($dox_options["listingColumns"] ) ) ) );
01926         }
01927         
01928         $renderedOptions .= "
01929         <form action=\"" . thisPageURL() . "\" method=\"POST\">
01930         <div class=\"documents-listing-options\">
01931                 <div class=\"documents-listing-options-label\">" . i18n("Show documents with the following ratings:") . "</div>
01932                 <div class=\"documents-listing-options-option\">";
01933         
01934         foreach( $dox_options["ratings"] as $key => $value )
01935         {
01936                 $checked = (in_array($key, $userShow)) ? " checked" : "";
01937                 $renderedOptions .= "
01938                 <label><input$checked type=\"checkbox\" name=\"showThis[$key]\" />" . $value . "</label>
01939                 " . drawCommand( i18n("Show"), i18n("Show this rating"), globalIDtoURL("documents/rating/" . $key));
01940         }
01941         
01942         $renderedOptions .= "
01943                 </div>
01944                 <div class=\"documents-listing-options-label\">" . i18n("Show these columns:") . "</div>
01945                 <div class=\"documents-listing-options-option\">";
01946         
01947         foreach( $dox_listingcolumns as $key => $value )
01948         {
01949                 $checked = (in_array($key, $userColumns)) ? " checked" : "";
01950                 $renderedOptions .= "
01951                 <label><input$checked type=\"checkbox\" name=\"showColumns[$key]\" />" . $value . "<label>";
01952         }
01953         
01954         $renderedOptions .= "
01955                 </div>
01956                 <input type=\"submit\" class=\"documents-listing-saveoptions\" name=\"saveOptions\" value=\"" . i18n("Save and apply") . "\" />
01957         </div>
01958         </form>";
01959         
01960         return $renderedOptions;
01961 }
01962 
01963 $modules_globalID[] = "globalID_documents";
01964 function globalID_documents( $splitID )
01965 {
01966         global $dox_options, $dox_show;
01967         $pageID = null;
01968         
01969         // Is the globalID directly aimed at this module?
01970         if( $splitID[0] == "documents" )
01971         {
01972                 $pageID = $dox_options["page_id"];
01973         }
01974         // Or is it aimed at the module's profile module?
01975         else if( $splitID[0] == "user" && $splitID[2] == "documents" )
01976         {
01977                 $_REQUEST["module"] = "profilemodule_documents";
01978                 $pageID = "13";
01979         }
01980         
01981         return $pageID;
01982 }
01983 
01992 function globalIDThumbnail_documents( $splitID )
01993 {
01994         global $module_folder;
01995         $data = array( "uri" => siteURL(true) . "$module_folder/documents/thumb.png", "width" => 64, "height" => 64 );
01996         return $data;
01997 }
01998 ?>

Generated on Sun Oct 26 20:33:13 2008 for The Travelsized Content Management System by  doxygen 1.5.5