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 SCRIPTS.'user_data.php';
00026
00033 class modified_nodes extends WebObject
00034 {
00041 function onRender()
00042 {
00043 $rs = new EditableRS('modified_nodes');
00044
00045
00046 $arr_books_admin = $this->get_arr_books_admin();
00047
00048
00049
00050 $this->add_is_admin($rs, $arr_books_admin);
00051
00052
00053 $arr_books_accr = $this->get_arr_books_accr($arr_books_admin);
00054
00055
00056
00057 $this->add_has_accr($rs, $arr_books_accr);
00058
00059
00060 global $webPage;
00061 $webPage->addRecordset($rs);
00062 }
00063
00065 function get_arr_books_admin()
00066 {
00067 $user_data = get_user_data(USER);
00068 $books = trim($user_data['books']);
00069 $arr_books = explode(',', $books);
00070
00071 $last_idx = sizeof($arr_books) - 1;
00072 if ($arr_books[$last_idx]=='') unset($arr_books[$last_idx]);
00073
00074 return $arr_books;
00075 }
00076
00081 function add_is_admin(&$rs, $arr_books_admin)
00082 {
00083 for ($i=0; $i < sizeof($arr_books_admin); $i++)
00084 {
00085 $book_id = $arr_books_admin[$i];
00086 $book_path = WS_BOOKS.$book_id.'/';
00087 $output = shell("ls $book_path/");
00088 $arr_langs = explode("\n", trim($output));
00089 for ($l=0; $l < sizeof($arr_langs); $l++)
00090 {
00091 $lng = $arr_langs[$l];
00092 $filename = "$book_path/$lng/modified_nodes.txt";
00093 if (!file_exists($filename)) continue;
00094 $arr_modified_nodes = file($filename);
00095 for ($n=0; $n < sizeof($arr_modified_nodes); $n++)
00096 {
00097 $node_path = $arr_modified_nodes[$n];
00098 $node_path = trim($node_path);
00099 $node_title = $this->get_title($book_id, $lng, $node_path);
00100 $rec = compact('book_id', 'lng', 'node_path', 'node_title');
00101 $rs->addRec($rec);
00102 }
00103 }
00104 }
00105 }
00106
00111 function get_arr_books_accr($arr_books_admin)
00112 {
00113 $arr_books_accr = array();
00114
00115 $accr_path = ADMIN.'access_rights/';
00116 $user = USER;
00117 $output = shell("find $accr_path -type f -name '$user'");
00118 $arr_files = explode("\n", $output);
00119
00120 for ($i=0; $i < sizeof($arr_files); $i++)
00121 {
00122 $file = trim($arr_files[$i]);
00123 if ($file=='') continue;
00124 $book_id = basename(dirname($file));
00125 if (!in_array($book_id, $arr_books_admin))
00126 {
00127 $arr_books_accr[] = $book_id;
00128 }
00129 }
00130
00131 return $arr_books_accr;
00132 }
00133
00138 function add_has_accr(&$rs, $arr_books_accr)
00139 {
00140 for ($i=0; $i < sizeof($arr_books_accr); $i++)
00141 {
00142 $book_id = $arr_books_accr[$i];
00143
00144
00145 $accr_file = ADMIN . "access_rights/$book_id/" . USER;
00146 $accr_rules = file($accr_file);
00147
00148
00149 $book_path = WS_BOOKS.$book_id.'/';
00150 $output = shell("ls $book_path/");
00151 $arr_langs = explode("\n", trim($output));
00152
00153
00154 for ($l=0; $l < sizeof($arr_langs); $l++)
00155 {
00156 $lng = $arr_langs[$l];
00157 $filename = "$book_path/$lng/modified_nodes.txt";
00158 if (!file_exists($filename)) continue;
00159 $arr_modified_nodes = file($filename);
00160 for ($n=0; $n < sizeof($arr_modified_nodes); $n++)
00161 {
00162 $node_path = $arr_modified_nodes[$n];
00163 $node_path = trim($node_path);
00164
00165
00166
00167 if ($this->has_approve_right($lng, $node_path, $accr_rules))
00168 {
00169 $node_title = $this->get_title($book_id,$lng,$node_path);
00170 $rec = compact('book_id','lng','node_path','node_title');
00171 $rs->addRec($rec);
00172 }
00173 }
00174 }
00175 }
00176 }
00177
00179 function has_approve_right($lng, $node_path, $arr_access_rights)
00180 {
00181
00182 $approve = false;
00183 for ($i=0; $i < sizeof($arr_access_rights); $i++)
00184 {
00185 $line = trim($arr_access_rights[$i]);
00186 list($access,$levels,$nodes,$langs) = explode(':', $line);
00187
00188
00189
00190 if ($this->node_match($node_path, $nodes)
00191 and $this->lang_match($lng, $langs))
00192 {
00193 $arr_levels = explode(',', $levels);
00194 if (in_array('approve', $arr_levels))
00195 {
00196 $approve = ($access=='allow' ? true : false);
00197 }
00198 }
00199 }
00200
00201 return $approve;
00202 }
00203
00211 function node_match($node_path, $node_list)
00212 {
00213 if (strtoupper($node_list)=='ALL') return true;
00214
00215 $arr_nodes = explode(',', $node_list);
00216 for ($i=0; $i < sizeof($arr_nodes); $i++)
00217 {
00218 $expr = $arr_nodes[$i];
00219 if (ereg('^'.$expr, $node_path)) return true;
00220 }
00221 }
00222
00229 function lang_match($lng, $lang_list)
00230 {
00231 if (strtoupper($lang_list)=='ALL') return true;
00232
00233 $arr_langs = explode(',', $lang_list);
00234 $match = in_array($lng, $arr_langs);
00235
00236 return $match;
00237 }
00238
00239 function get_title($book_id, $lng, $node_path)
00240 {
00241 $cache_path = WS_CACHE."$book_id/$lng/";
00242 $navigation_file = $cache_path.$node_path."navigation.txt";
00243 $line = shell("grep full_title $navigation_file");
00244 $arr = split('=', chop($line), 2);
00245 $title = $arr[1];
00246 if ($title=='') $title = 'Table Of Contents';
00247 return $title;
00248 }
00249 }
00250 ?>