uEdit.php

Go to the documentation of this file.
00001 <?php
00002   /*
00003    This file is part of DocBookWiki.  DocBookWiki is a web application
00004    that displays and edits DocBook documents.
00005 
00006    Copyright (C) 2004, 2005, 2006, 2007
00007    Dashamir Hoxha, dashohoxha@users.sourceforge.net
00008 
00009    DocBookWiki is free software; you can redistribute it and/or modify
00010    it under the  terms of the GNU General  Public License as published
00011    by the Free  Software Foundation; either version 2  of the License,
00012    or (at your option) any later version.
00013 
00014    DocBookWiki is distributed in the  hope that it will be useful, but
00015    WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
00016    MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
00017    General Public License for more details.
00018 
00019    You should have  received a copy of the  GNU General Public License
00020    along  with  DocBookWiki;  if  not,  write  to  the  Free  Software
00021    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022    USA
00023   */
00024 
00030 class uEdit extends WebObject
00031 {
00033   function on_save($event_args)
00034   {
00035     $edit_rights = $event_args['edit_rights'];
00036 
00037     //ToDo: validate the format
00038     //...
00039 
00040     //save them
00041     $username = WebApp::getSVar('uList->currentUser');
00042     $book_id = WebApp::getSVar('books->selected_book');
00043     $fname = "templates/admin/access_rights/$book_id/$username";
00044     write_file($fname, $edit_rights);
00045   }
00046 
00047   function onRender()
00048   {
00049     $this->add_user_data();
00050     $this->add_edit_rights();
00051     $this->add_rs_langs();
00052     $this->add_rs_nodes();
00053   }
00054 
00056   function add_user_data()
00057   {
00058     include_once SCRIPTS.'user_data.php';
00059     $username = WebApp::getSVar('uList->currentUser');
00060     $user_data = get_user_data($username);
00061     unset($user_data['password']);
00062     WebApp::addVars($user_data);
00063   }
00064 
00065   function add_edit_rights()
00066   {
00067     $username = WebApp::getSVar('uList->currentUser');
00068     if ($username==UNDEFINED)
00069       {
00070         $edit_rights = '';
00071       }
00072     else
00073       {
00074         //get the user edit rights and add them to the template
00075         $book_id = WebApp::getSVar('books->selected_book');
00076         $cmd = SCRIPTS."books/get_user_rights.sh $book_id $username";
00077         $edit_rights = shell($cmd);
00078         if (ereg('No such file or directory', $edit_rights)) 
00079           $edit_rights = '';
00080       }
00081     if ($edit_rights=='')  $edit_rights = ' ';
00082     WebApp::addVar('edit_rights', $edit_rights);
00083   }
00084 
00085   function add_rs_langs()
00086   {
00087     $rs = new EditableRS('langs');
00088 
00089     $book_id = WebApp::getSVar('books->selected_book');
00090     $arr_langs = $this->get_langs($book_id);
00091 
00092     for ($i=0; $i < sizeof($arr_langs); $i++)
00093       {
00094         $lng = $arr_langs[$i];
00095         $rs->addRec(array('lng'=>$lng));
00096       }
00097 
00098     global $webPage;
00099     $webPage->addRecordset($rs);
00100   }
00101 
00102   function add_rs_nodes()
00103   {
00104     //get book nodes
00105     $book_id = WebApp::getSVar('books->selected_book');
00106     $arr_langs = $this->get_langs($book_id);
00107     $lng = $arr_langs[0];
00108     $index_xml = BOOKS."$book_id/$lng/index.xml";
00109     $nodes = shell(SCRIPTS."books/get_book_nodes.sh '$index_xml'");
00110 
00111     //fill the recordset
00112     $rs = new EditableRS('nodes');
00113     $arr_nodes = explode("\n", $nodes);
00114     for ($i=0; $i < sizeof($arr_nodes); $i++)
00115       {
00116         $node_id = $arr_nodes[$i];
00117         $rs->addRec(array('node_id'=>$node_id));
00118       }
00119 
00120     //add the recodset to the page
00121     global $webPage;
00122     $webPage->addRecordset($rs);
00123   }
00124 
00129   function get_langs($book_id)
00130   {
00131     $book_path = BOOKS.$book_id.'/';
00132     if (!file_exists($book_path))  return array();
00133 
00134     $langs = shell("ls $book_path");
00135     $arr_langs = explode("\n", chop($langs));
00136 
00137     return $arr_langs;
00138   }
00139 }
00140 ?>

Generated on Wed Jan 9 08:27:32 2008 for DokBookWiki by  doxygen 1.5.2