00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 include_once dirname(__FILE__).'/funcs.php';
00026
00032 class docbook extends WebObject
00033 {
00034 function init()
00035 {
00036 $this->addSVar('book_id', UNDEFINED);
00037 $this->addSVar('node_path', './');
00038 $this->addSVar('languages', 'en,sq_AL');
00039 $this->addSVar('lng', 'en');
00040 $this->addSVar('mode', 'view');
00041 }
00042
00043 function on_set_node($event_args)
00044 {
00045 $node_path = $event_args['node_path'];
00046 $this->setSVar('node_path', $node_path);
00047 }
00048
00049 function on_set_node_id($event_args)
00050 {
00051 $id = $event_args['node_id'];
00052 $path = process_index('edit/get_node_path.xsl', array('id'=>$id));
00053 $this->setSVar('node_path', $path);
00054 }
00055
00056 function on_set_mode($event_args)
00057 {
00058 $mode = $event_args['mode'];
00059 $access_vars = $this->get_button_vars();
00060 $access_vars['view'] = 'true';
00061 if ($access_vars[$mode] == 'true')
00062 {
00063 $this->setSVar('mode', $mode);
00064 }
00065 else
00066 {
00067 WebApp::message(T_("Don't have access."));
00068 }
00069 }
00070
00071 function on_set_lng($event_args)
00072 {
00073 $lng = $event_args['lng'];
00074 $this->setSVar('lng', $lng);
00075
00076
00077 $book_id = $this->getSVar('book_id');
00078 $book_title = main::get_book_title($book_id, $lng);
00079 WebApp::setSVar('book_title', $book_title);
00080 }
00081
00082 function onParse()
00083 {
00084 $mode = $this->getSVar('mode');
00085 WebApp::addVar('node', "$mode/$mode.html");
00086
00087
00088 $this->add_accessright_vars();
00089 }
00090
00092 function add_accessright_vars()
00093 {
00094 WebApp::addGlobalVar('is_admin', $this->is_admin());
00095 list($can_edit, $can_approve) = $this->get_edit_rights();
00096 WebApp::addGlobalVar('can_edit', $can_edit);
00097 WebApp::addGlobalVar('can_approve', $can_approve);
00098 }
00099
00104 function is_admin()
00105 {
00106
00107 if (SU=='true') return 'true';
00108
00109
00110 $record = shell(SCRIPTS.'users/get_user.sh '.USER);
00111 $record = trim($record);
00112 $arr_fields = explode(':', $record);
00113 $book_list = $arr_fields[4];
00114 $arr_books = explode(',', $book_list);
00115
00116 $book_id = $this->getSVar('book_id');
00117 $is_admin = (in_array($book_id, $arr_books));
00118 return ($is_admin ? 'true' : 'false');
00119 }
00120
00121 function onRender()
00122 {
00123
00124 $node_path = $this->getSVar('node_path');
00125 $vars = get_arr_navigation($node_path);
00126 if ($vars['this_full_title']=='')
00127 $vars['this_full_title'] = T_("Table Of Contents");
00128 if (trim($vars['this_full_title'])=='Info /')
00129 $vars['this_full_title'] = T_("Info");
00130 WebApp::addVars($vars);
00131 WebApp::addVar('info_path', './INFO/');
00132 WebApp::addVar('toc_path', './');
00133
00134
00135
00136 WebApp::addVars($this->get_button_vars());
00137
00138
00139 $arr_state = get_node_state();
00140 $locked = locked_by_somebody($arr_state);
00141 $str_locked = ($locked ? 'locked' : 'unlocked');
00142 WebApp::addVar('locked', $str_locked);
00143 WebApp::addVar('status', $arr_state['status']);
00144 }
00145
00151 function get_button_vars()
00152 {
00153 $is_admin = WebApp::getVar('is_admin');
00154 if ($is_admin==UNDEFINED)
00155 {
00156 $this->add_accessright_vars();
00157 $is_admin = WebApp::getVar('is_admin');
00158 }
00159
00160 if ( !defined('EDIT') )
00161 {
00162
00163 $edit = 'false';
00164 $approve = 'false';
00165 $admin = 'false';
00166 }
00167 else if ($is_admin=='true')
00168 {
00169
00170
00171 $edit = 'true';
00172 $approve = 'true';
00173
00174
00175 $node_path = WebApp::getSVar('docbook->node_path');
00176 $admin = ($node_path=='./' ? 'true' : 'false');
00177 }
00178 else
00179 {
00180
00181
00182 $edit = WebApp::getVar('can_edit');
00183 $approve = WebApp::getVar('can_approve');
00184
00185
00186 $admin = 'false';
00187 }
00188
00189 $vars = array('edit'=>$edit, 'approve'=>$approve, 'admin'=>$admin);
00190 return $vars;
00191 }
00192
00201 function get_edit_rights()
00202 {
00203
00204 $edit = 'false';
00205 $approve = 'false';
00206
00207 if (!defined('EDIT')) return array($edit, $approve);
00208
00209
00210 $book_id = $this->getSVar('book_id');
00211 $accr_file = ADMIN."access_rights/$book_id/".USER;
00212 $arr_lines = (file_exists($accr_file) ? file($accr_file) : array());
00213
00214
00215
00216 for ($i=0; $i < sizeof($arr_lines); $i++)
00217 {
00218 $line = $arr_lines[$i];
00219 $line = trim($line);
00220 list($access,$levels,$nodes,$langs) = explode(':', $line);
00221
00222
00223
00224 if ($this->node_match($nodes) and $this->lang_match($langs))
00225 {
00226 $value = ($access=='allow' ? 'true' : 'false');
00227 $arr_levels = explode(',', $levels);
00228 if (in_array('edit', $arr_levels)) $edit = $value;
00229 if (in_array('approve', $arr_levels)) $approve = $value;
00230 }
00231 }
00232
00233 return array($edit, $approve);
00234 }
00235
00243 function node_match($node_list)
00244 {
00245 if (strtoupper($node_list)=='ALL') return true;
00246
00247 $node_path = $this->getSVar('node_path');
00248 $arr_nodes = explode(',', $node_list);
00249 for ($i=0; $i < sizeof($arr_nodes); $i++)
00250 {
00251 $expr = $arr_nodes[$i];
00252 if (ereg('^'.$expr, $node_path)) return true;
00253 }
00254 }
00255
00262 function lang_match($lang_list)
00263 {
00264 if (strtoupper($lang_list)=='ALL') return true;
00265
00266 $lng = $this->getSVar('lng');
00267 $arr_langs = explode(',', $lang_list);
00268 $match = in_array($lng, $arr_langs);
00269
00270 return $match;
00271 }
00272 }
00273 ?>