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
00032 class edit_menu extends WebObject
00033 {
00034 function init()
00035 {
00036
00037 $this->addSVar('item_id', 'menu');
00038 $this->addSVar('item_bookid', '');
00039 $this->addSVar('item_caption', '');
00040
00041
00042 $this->addSVar('clipboard', '');
00043 }
00044
00046 function on_select($event_args)
00047 {
00048 $item_id = $event_args['item_id'];
00049 $this->select_item($item_id);
00050 }
00051
00056 function select_item($item_id)
00057 {
00058
00059 $output = $this->transform('get_bookid.xsl', array('id'=>$item_id));
00060 list($bookid, $caption) = split(' ', $output, 2);
00061
00062
00063 $this->setSVar('item_id', $item_id);
00064 $this->setSVar('item_bookid', $bookid);
00065 $this->setSVar('item_caption', $caption);
00066 }
00067
00068 function transform_menu($transformer, $arr_params =array())
00069 {
00070
00071 $new_menu = $this->transform($transformer, $arr_params);
00072
00073
00074 $menu_path = ADMIN.'edit_menu/menu/';
00075 write_file($menu_path.'menu.xml', $new_menu);
00076 }
00077
00082 function transform($transformer, $arr_params =array())
00083 {
00084
00085 $params = '';
00086 while (list($p_name, $p_value) = each($arr_params))
00087 {
00088 $params .= "--stringparam $p_name \"$p_value\" ";
00089 }
00090
00091
00092 $menu_path = ADMIN.'edit_menu/menu/';
00093 $menu_xml = $menu_path.'menu.xml';
00094 $xsl_file = $menu_path."xsl/$transformer";
00095 $result = shell("xsltproc $params $xsl_file $menu_xml");
00096
00097
00098 return $result;
00099 }
00100
00102 function on_update($event_args)
00103 {
00104 $params = $event_args;
00105 $item_id = $this->getSVar('item_id');
00106 $params['id'] = $item_id;
00107 $this->transform_menu('update.xsl', $params);
00108 $this->select_item($item_id);
00109 }
00110
00112 function on_delete($event_args)
00113 {
00114 $params['id'] = $this->getSVar('item_id');
00115 $parent_id = $this->transform('get_parent_id.xsl', $params);
00116 $this->transform_menu('delete.xsl', $params);
00117 $this->select_item($parent_id);
00118 }
00119
00121 function on_move_up($event_args)
00122 {
00123 $params['id'] = $event_args['item_id'];
00124 $this->transform_menu('move_up.xsl', $params);
00125 }
00126
00128 function on_move_down($event_args)
00129 {
00130 $params['id'] = $event_args['item_id'];
00131 $this->transform_menu('move_down.xsl', $params);
00132 }
00133
00135 function on_add_subitem($event_args)
00136 {
00137 $params = $event_args;
00138 $params['id'] = $this->getSVar('item_id');
00139 $this->transform_menu('add_subitem.xsl', $params);
00140 }
00141
00143 function on_paste($event_args)
00144 {
00145 $clipboard = $this->getSVar('clipboard');
00146 $clipboard_items = explode("\n", $clipboard);
00147
00148
00149 $arr_items = array();
00150 for ($i=0; $i < sizeof($clipboard_items); $i++)
00151 {
00152 $item = trim($clipboard_items[$i]);
00153 if ($item=='') continue;
00154 if (in_array($item, $arr_items)) continue;
00155 $arr_items[] = $item;
00156 }
00157
00158
00159 $item_id = $this->getSVar('item_id');
00160 for ($i=0; $i < sizeof($arr_items); $i++)
00161 {
00162 $item = $arr_items[$i];
00163 list($copy_id, $bookid, $caption) = split(':', $item, 3);
00164
00165
00166 $params['id'] = $item_id;
00167 $params['copy_id'] = $copy_id;
00168 $this->transform_menu('copy_item.xsl', $params);
00169 }
00170 }
00171
00173 function on_apply($event_args)
00174 {
00175
00176 $menu_xml = MENU.'menu.xml';
00177 $edit_menu_xml = ADMIN.'edit_menu/menu/menu.xml';
00178 shell("cp $edit_menu_xml $menu_xml");
00179
00180
00181 $menu_items = $this->transform('menu_items.xsl');
00182 write_file(MENU.'menu_items.js', $menu_items);
00183
00184
00185 $book_list = $this->transform('book_list.xsl');
00186 write_file(MENU.'book_list.php', $book_list);
00187
00188
00189 $this->select_item('menu');
00190 }
00191
00193 function on_cancel($event_args)
00194 {
00195 $menu_xml = MENU.'menu.xml';
00196 $edit_menu_xml = ADMIN.'edit_menu/menu/menu.xml';
00197 shell("cp $menu_xml $edit_menu_xml");
00198
00199
00200 $this->select_item('menu');
00201 }
00202
00203 function onRender()
00204 {
00205 $this->add_subitems_rs();
00206 $this->add_books_rs();
00207 }
00208
00210 function add_subitems_rs()
00211 {
00212
00213 $item_id = $this->getSVar('item_id');
00214 $items = $this->transform('subitems.xsl', array('id'=>$item_id));
00215 $arr_lines = explode("\n", $items);
00216
00217
00218 $rs = new EditableRS('subitems');
00219 for ($i=0; $i < sizeof($arr_lines); $i++)
00220 {
00221 list($id, $bookid, $caption) = split(' ', $arr_lines[$i], 3);
00222 if ($id=='') continue;
00223 $rs->addRec(compact('id', 'bookid', 'caption'));
00224 }
00225 global $webPage;
00226 $webPage->addRecordset($rs);
00227 }
00228
00233 function add_books_rs()
00234 {
00235
00236 $rs = new EditableRS('booklist');
00237 $rs->addRec(array('id'=>'', 'label'=>'----- '.T_("Select").' -----'));
00238 $output = shell('ls '.BOOKS);
00239 $arr_lines = explode("\n", $output);
00240 for ($i=0; $i < sizeof($arr_lines); $i++)
00241 {
00242 $book_id = trim($arr_lines[$i]);
00243 if ($book_id=='') continue;
00244 $rs->addRec(array('id' => $book_id, 'label' => $book_id));
00245 }
00246 global $webPage;
00247 $webPage->addRecordset($rs);
00248 }
00249 }
00250 ?>