[phpwebapp-commits] CVS: web_app/boxes/menu/edit edit_menu.php,1.1,1.2
Brought to you by:
dashohoxha
From: Dashamir H. <das...@us...> - 2004-07-22 16:25:49
|
Update of /cvsroot/phpwebapp/web_app/boxes/menu/edit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9224/boxes/menu/edit Modified Files: edit_menu.php Log Message: reformated and modified the copyleft notice Index: edit_menu.php =================================================================== RCS file: /cvsroot/phpwebapp/web_app/boxes/menu/edit/edit_menu.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** edit_menu.php 16 Jul 2004 07:41:39 -0000 1.1 --- edit_menu.php 22 Jul 2004 16:25:38 -0000 1.2 *************** *** 1,35 **** <?php class edit_menu extends WebObject { function init() ! { ! //the menu item that is being edited, initially the root ! $this->addSVar('item_id', 'menu'); ! } /** select an item for editing */ function on_select($event_args) ! { ! $item_id = $event_args['item_id']; ! $this->setSVar('item_id', $item_id); ! } function transform_menu($transformer, $arr_params =array()) ! { ! //apply the transformer and get the new menu ! $new_menu = $this->transform($transformer, $arr_params); ! //save the transformed menu to a tmp file ! $tmpfname = tempnam("/tmp", "menu"); ! $fp = fopen($tmpfname, 'w'); ! fputs($fp, $new_menu); ! fclose($fp); ! //move to menu.xml and set permissions ! $menu_xml = MENU.'edit/menu.xml'; ! shell_exec("./wrapper mv $tmpfname $menu_xml"); ! shell_exec("./wrapper chown dasho.dasho $menu_xml"); ! shell_exec("./wrapper chmod 664 $menu_xml"); ! } /** --- 1,56 ---- <?php + /* + This file is part of phpWebApp, which is a framework for building web + application based on relational databases. + + Copyright 2001,2002,2003,2004 Dashamir Hoxha, das...@us... + + phpWebApp is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + phpWebApp is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with phpWebApp; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + class edit_menu extends WebObject { function init() ! { ! //the menu item that is being edited, initially the root ! $this->addSVar('item_id', 'menu'); ! } /** select an item for editing */ function on_select($event_args) ! { ! $item_id = $event_args['item_id']; ! $this->setSVar('item_id', $item_id); ! } function transform_menu($transformer, $arr_params =array()) ! { ! //apply the transformer and get the new menu ! $new_menu = $this->transform($transformer, $arr_params); ! //save the transformed menu to a tmp file ! $tmpfname = tempnam("/tmp", "menu"); ! $fp = fopen($tmpfname, 'w'); ! fputs($fp, $new_menu); ! fclose($fp); ! //move to menu.xml and set permissions ! $menu_xml = MENU.'edit/menu.xml'; ! shell_exec("./wrapper mv $tmpfname $menu_xml"); ! shell_exec("./wrapper chown dasho.dasho $menu_xml"); ! shell_exec("./wrapper chmod 664 $menu_xml"); ! } /** *************** *** 38,185 **** */ function transform($transformer, $arr_params =array()) ! { ! //construct the string $params ! $params = ''; ! while (list($p_name, $p_value) = each($arr_params)) ! { ! $params .= "--stringparam $p_name \"$p_value\" "; ! } ! //apply the $transformer with $params to menu.xml ! $menu_xml = MENU.'edit/menu.xml'; ! $xsl_file = MENU."edit/xsl/$transformer"; ! $result = shell_exec("xsltproc $params $xsl_file $menu_xml 2>&1"); ! //print "<xmp>$result</xmp>\n"; ! return $result; ! } /** save modifications in id and caption of the current item */ function on_update($event_args) ! { ! //if the id has changed, check that the new id does not exist ! $item_id = $this->getSVar('item_id'); ! $new_id = $event_args['new_id']; ! $output = $this->transform('get_id.xsl', array('id'=>$new_id)); ! if ($new_id <> $item_id and $output==$new_id) ! { ! WebApp::message("Another menu item with id '$new_id' already exists."); ! return; ! } ! $params = $event_args; ! $params['id'] = $item_id; ! $this->transform_menu('update.xsl', $params); ! $this->setSVar('item_id', $new_id); ! } /** delete the current item and set the parent item as the current one */ function on_delete($event_args) ! { ! $params['id'] = $this->getSVar('item_id'); ! $parent_id = $this->transform('get_parent_id.xsl', $params); ! $this->transform_menu('delete.xsl', $params); ! $this->setSVar('item_id', $parent_id); ! } /** move the current item up */ function on_move_up($event_args) ! { ! $params['id'] = $event_args['item_id']; ! $this->transform_menu('move_up.xsl', $params); ! } /** move the current item down */ function on_move_down($event_args) ! { ! $params['id'] = $event_args['item_id']; ! $this->transform_menu('move_down.xsl', $params); ! } /** add a new subitem to the current item */ function on_add_subitem($event_args) ! { ! //check that the new id does not exist ! $new_id = $event_args['new_id']; ! $output = $this->transform('get_id.xsl', array('id'=>$new_id)); ! if ($output==$new_id) ! { ! WebApp::message("Another menu item with id '$new_id' already exists."); ! return; ! } ! $params = $event_args; ! $params['id'] = $this->getSVar('item_id'); ! $this->transform_menu('add_subitem.xsl', $params); ! } /** apply the modifications to the main menu */ function on_apply($event_args) ! { ! $menu_xml = MENU.'menu.xml'; ! $edit_menu_xml = MENU.'edit/menu.xml'; ! shell_exec("./wrapper cp $edit_menu_xml $menu_xml"); ! //get menu_items.js ! $menu_items = $this->transform('menu_items.xsl'); ! //save it to a tmp file ! $tmpfname = tempnam("/tmp", "menu"); ! $fp = fopen($tmpfname, 'w'); ! fputs($fp, $menu_items); ! fclose($fp); ! //move to menu_items.js and set permissions ! $menu_items_js = MENU.'menu_items.js'; ! shell_exec("./wrapper mv $tmpfname $menu_items_js"); ! shell_exec("./wrapper chown dasho.dasho $menu_items_js"); ! shell_exec("./wrapper chmod 664 $menu_items_js"); ! //get book_list.php ! $book_list = $this->transform('book_list.xsl'); ! //save it to a tmp file ! $tmpfname = tempnam("/tmp", "menu"); ! $fp = fopen($tmpfname, 'w'); ! fputs($fp, $book_list); ! fclose($fp); ! //move to book_list_php and set permissions ! $book_list_php = MENU.'book_list.php'; ! shell_exec("./wrapper mv $tmpfname $book_list_php"); ! shell_exec("./wrapper chown dasho.dasho $book_list_php"); ! shell_exec("./wrapper chmod 664 $book_list_php"); ! } /** discard any modifications and get a copy of the main menu */ function on_cancel($event_args) ! { ! $menu_xml = MENU.'menu.xml'; ! $edit_menu_xml = MENU.'edit/menu.xml'; ! shell_exec("./wrapper cp $menu_xml $edit_menu_xml"); ! } function onRender() ! { ! //this variable makes visible the edit menu in menu.html ! WebApp::addGlobalVar('edit_menu_visible', 'true'); ! $item_id = $this->getSVar('item_id'); ! //get the selected item and subitems ! $items = $this->transform('subitems.xsl', array('id'=>$item_id)); ! $arr_lines = explode("\n", $items); ! //get the caption of the selected item (from the first line) ! list($id, $item_caption) = split(' ', $arr_lines[0], 2); ! WebApp::addVar('item_caption', $item_caption); ! //create a recordset with id-s and captions of the subitems ! $rs = new EditableRS('subitems'); ! for ($i=1; $i < sizeof($arr_lines); $i++) ! { ! list($id, $caption) = split(' ', $arr_lines[$i], 2); ! if ($id=='') continue; ! $rs->addRec(compact('id','caption')); ! } ! global $webPage; ! $webPage->addRecordset($rs); ! } } ?> \ No newline at end of file --- 59,206 ---- */ function transform($transformer, $arr_params =array()) ! { ! //construct the string $params ! $params = ''; ! while (list($p_name, $p_value) = each($arr_params)) ! { ! $params .= "--stringparam $p_name \"$p_value\" "; ! } ! //apply the $transformer with $params to menu.xml ! $menu_xml = MENU.'edit/menu.xml'; ! $xsl_file = MENU."edit/xsl/$transformer"; ! $result = shell_exec("xsltproc $params $xsl_file $menu_xml 2>&1"); ! //print "<xmp>$result</xmp>\n"; ! return $result; ! } /** save modifications in id and caption of the current item */ function on_update($event_args) ! { ! //if the id has changed, check that the new id does not exist ! $item_id = $this->getSVar('item_id'); ! $new_id = $event_args['new_id']; ! $output = $this->transform('get_id.xsl', array('id'=>$new_id)); ! if ($new_id <> $item_id and $output==$new_id) ! { ! WebApp::message("Another menu item with id '$new_id' already exists."); ! return; ! } ! $params = $event_args; ! $params['id'] = $item_id; ! $this->transform_menu('update.xsl', $params); ! $this->setSVar('item_id', $new_id); ! } /** delete the current item and set the parent item as the current one */ function on_delete($event_args) ! { ! $params['id'] = $this->getSVar('item_id'); ! $parent_id = $this->transform('get_parent_id.xsl', $params); ! $this->transform_menu('delete.xsl', $params); ! $this->setSVar('item_id', $parent_id); ! } /** move the current item up */ function on_move_up($event_args) ! { ! $params['id'] = $event_args['item_id']; ! $this->transform_menu('move_up.xsl', $params); ! } /** move the current item down */ function on_move_down($event_args) ! { ! $params['id'] = $event_args['item_id']; ! $this->transform_menu('move_down.xsl', $params); ! } /** add a new subitem to the current item */ function on_add_subitem($event_args) ! { ! //check that the new id does not exist ! $new_id = $event_args['new_id']; ! $output = $this->transform('get_id.xsl', array('id'=>$new_id)); ! if ($output==$new_id) ! { ! WebApp::message("Another menu item with id '$new_id' already exists."); ! return; ! } ! $params = $event_args; ! $params['id'] = $this->getSVar('item_id'); ! $this->transform_menu('add_subitem.xsl', $params); ! } /** apply the modifications to the main menu */ function on_apply($event_args) ! { ! $menu_xml = MENU.'menu.xml'; ! $edit_menu_xml = MENU.'edit/menu.xml'; ! shell_exec("./wrapper cp $edit_menu_xml $menu_xml"); ! //get menu_items.js ! $menu_items = $this->transform('menu_items.xsl'); ! //save it to a tmp file ! $tmpfname = tempnam("/tmp", "menu"); ! $fp = fopen($tmpfname, 'w'); ! fputs($fp, $menu_items); ! fclose($fp); ! //move to menu_items.js and set permissions ! $menu_items_js = MENU.'menu_items.js'; ! shell_exec("./wrapper mv $tmpfname $menu_items_js"); ! shell_exec("./wrapper chown dasho.dasho $menu_items_js"); ! shell_exec("./wrapper chmod 664 $menu_items_js"); ! //get book_list.php ! $book_list = $this->transform('book_list.xsl'); ! //save it to a tmp file ! $tmpfname = tempnam("/tmp", "menu"); ! $fp = fopen($tmpfname, 'w'); ! fputs($fp, $book_list); ! fclose($fp); ! //move to book_list_php and set permissions ! $book_list_php = MENU.'book_list.php'; ! shell_exec("./wrapper mv $tmpfname $book_list_php"); ! shell_exec("./wrapper chown dasho.dasho $book_list_php"); ! shell_exec("./wrapper chmod 664 $book_list_php"); ! } /** discard any modifications and get a copy of the main menu */ function on_cancel($event_args) ! { ! $menu_xml = MENU.'menu.xml'; ! $edit_menu_xml = MENU.'edit/menu.xml'; ! shell_exec("./wrapper cp $menu_xml $edit_menu_xml"); ! } function onRender() ! { ! //this variable makes visible the edit menu in menu.html ! WebApp::addGlobalVar('edit_menu_visible', 'true'); ! $item_id = $this->getSVar('item_id'); ! //get the selected item and subitems ! $items = $this->transform('subitems.xsl', array('id'=>$item_id)); ! $arr_lines = explode("\n", $items); ! //get the caption of the selected item (from the first line) ! list($id, $item_caption) = split(' ', $arr_lines[0], 2); ! WebApp::addVar('item_caption', $item_caption); ! //create a recordset with id-s and captions of the subitems ! $rs = new EditableRS('subitems'); ! for ($i=1; $i < sizeof($arr_lines); $i++) ! { ! list($id, $caption) = split(' ', $arr_lines[$i], 2); ! if ($id=='') continue; ! $rs->addRec(compact('id','caption')); ! } ! global $webPage; ! $webPage->addRecordset($rs); ! } } ?> \ No newline at end of file |