admin/addbook/book_list/book_list.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 
00031 class book_list extends WebObject
00032 {
00033   function init()
00034   {
00035     $this->addSVar('visible', 'false');
00036   }
00037 
00038   function on_set_visible($event_args)
00039   {
00040     $visible = $event_args['visible'];
00041     $this->setSVar('visible', $visible);
00042   }
00043 
00044   function on_delete($event_args)
00045   {
00046     $book_id = $event_args['book_id'];
00047     $lng = $event_args['lng'];
00048     $clean_sh = CONTENT.'clean.sh';
00049     $output = shell(CONTENT."clean.sh $book_id $lng");
00050     WebApp::debug_msg("<xmp>$output</xmp>");
00051   }
00052 
00053   function onRender()
00054   {
00055     $this->add_recordsets();
00056   }
00057 
00058   function add_recordsets()
00059   {
00060     global $webPage;
00061 
00062     //the number of columns/chunks
00063     $nr_cols = 3; 
00064 
00065     //add a recordset for the columns
00066     $rs_cols = new EditableRS("cols");
00067 
00068     //get the list of books
00069     $fname = CONTENT.'books/book_list';
00070     $arr_lines = file($fname);
00071     $nr_chunks = sizeof($arr_lines) / $nr_cols;
00072     if (sizeof($arr_lines) % $nr_cols)  $nr_chunks++;
00073     $arr_chunks = array_chunk($arr_lines, $nr_chunks);
00074 
00075     //create, fill and add a recordset for each column/chunk
00076     for ($i=0; $i < sizeof($arr_chunks); $i++)
00077       {
00078         //create a new recordset for the chunk
00079         $rs = new EditableRS("books_$i");
00080 
00081         //add the items of the chunk in the recordset
00082         $chunk = $arr_chunks[$i];
00083         for ($j=0; $j < sizeof($chunk); $j++)
00084           {
00085             $line = $chunk[$j];
00086             if (trim($line)=='')  continue;
00087 
00088             //get book_id, lng and title of the book
00089             list($book_id, $lng, $title) = split(':', $line, 3);
00090             $title = trim($title);
00091 
00092             //add a record for this book
00093             $rs->addRec(compact('book_id', 'lng', 'title'));
00094           }
00095 
00096         //add the recordset to the webPage
00097         $webPage->addRecordset($rs);
00098 
00099         //add a record for this column/chunk
00100         $rs_cols->addRec(array('nr'=> $i));
00101       }
00102 
00103     //add the column recordset to the webPage
00104     $webPage->addRecordset($rs_cols);
00105   }
00106 }
00107 ?>

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