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 books extends WebObject 00031 { 00032 function init() 00033 { 00034 $arr_book_list = $this->get_book_list_arr(); 00035 $this->addSVar('selected_book', $arr_book_list[0]); 00036 } 00037 00038 function on_select($event_args) 00039 { 00040 $book_id = $event_args['book_id']; 00041 $this->setSVar('selected_book', $book_id); 00042 } 00043 00044 function onRender() 00045 { 00046 $this->add_book_title(); 00047 $this->add_book_list_rs(); 00048 } 00049 00050 function add_book_title() 00051 { 00052 $book_list = CONTENT.'books/book_list'; 00053 $book_id = $this->getSVar('selected_book'); 00054 00055 $lng = WebApp::getSVar('language'); 00056 $book_title = shell("grep '^$book_id:$lng:' $book_list | cut -d: -f3"); 00057 00058 if ($book_title=='') 00059 { 00060 $lng = 'en'; 00061 $book_title = shell("grep '^$book_id:$lng:' $book_list | cut -d: -f3"); 00062 } 00063 00064 if ($book_title=='') 00065 { 00066 $book_title = shell("grep '^$book_id:' $book_list | head -n 1 | cut -d: -f3"); 00067 } 00068 00069 WebApp::addVar('book_title', trim($book_title)); 00070 } 00071 00072 function add_book_list_rs() 00073 { 00074 //get $arr_books 00075 $book_list = CONTENT.'books/book_list'; 00076 $books = shell("cat $book_list | cut -d: -f1 | uniq"); 00077 $arr_books = explode("\n", trim($books)); 00078 00079 $rs = new EditableRS('book_list'); 00080 $arr_book_list = $this->get_book_list_arr(); 00081 for ($i=0; $i < sizeof($arr_book_list); $i++) 00082 { 00083 $book_id = $arr_book_list[$i]; 00084 if (in_array($book_id, $arr_books)) 00085 { 00086 $rec = array('id'=>$book_id, 'label'=>$book_id); 00087 $rs->addRec($rec); 00088 } 00089 } 00090 global $webPage; 00091 $webPage->addRecordset($rs); 00092 } 00093 00094 function get_book_list_arr() 00095 { 00096 $record = shell(SCRIPTS.'users/get_user.sh '.USER); 00097 $record = trim($record); 00098 $fields = explode(':', $record); 00099 $book_list = $fields[4]; 00100 $arr = explode(',', $book_list); 00101 00102 return $arr; 00103 } 00104 } 00105 ?>