From: <sy...@us...> - 2008-06-11 15:09:35
|
Revision: 13199 http://tikiwiki.svn.sourceforge.net/tikiwiki/?rev=13199&view=rev Author: sylvieg Date: 2008-06-11 08:09:02 -0700 (Wed, 11 Jun 2008) Log Message: ----------- [MOD]menu: possibility to csv import/export options Modified Paths: -------------- branches/1.10/lib/menubuilder/menulib.php branches/1.10/lib/tikilib.php branches/1.10/templates/tiki-admin_menu_options.tpl branches/1.10/tiki-admin_menu_options.php Modified: branches/1.10/lib/menubuilder/menulib.php =================================================================== --- branches/1.10/lib/menubuilder/menulib.php 2008-06-11 14:53:48 UTC (rev 13198) +++ branches/1.10/lib/menubuilder/menulib.php 2008-06-11 15:09:02 UTC (rev 13199) @@ -64,7 +64,7 @@ return $max; } - function replace_menu_option($menuId, $optionId, $name, $url, $type, $position, $section, $perm, $groupname, $level=0) { + function replace_menu_option($menuId, $optionId, $name, $url, $type='o', $position=1, $section='', $perm='', $groupname='', $level=0) { if ($optionId) { $query = "update `tiki_menu_options` set `name`=?,`url`=?,`type`=?,`position`=?,`section`=?,`perm`=?,`groupname`=?,`userlevel`=? where `optionId`=?"; $bindvars=array($name,$url,$type,(int)$position,$section,$perm,$groupname,$level,$optionId); Modified: branches/1.10/lib/tikilib.php =================================================================== --- branches/1.10/lib/tikilib.php 2008-06-11 14:53:48 UTC (rev 13198) +++ branches/1.10/lib/tikilib.php 2008-06-11 15:09:02 UTC (rev 13199) @@ -1809,7 +1809,7 @@ } /*shared*/ - function list_menu_options($menuId, $offset, $maxRecords, $sort_mode, $find, $full=false,$level=0) { + function list_menu_options($menuId, $offset=0, $maxRecords=-1, $sort_mode='position_asc', $find='', $full=false, $level=0) { global $smarty,$user, $tiki_p_admin, $prefs; global $wikilib; include_once('lib/wiki/wikilib.php'); $ret = array(); Modified: branches/1.10/templates/tiki-admin_menu_options.tpl =================================================================== --- branches/1.10/templates/tiki-admin_menu_options.tpl 2008-06-11 14:53:48 UTC (rev 13198) +++ branches/1.10/templates/tiki-admin_menu_options.tpl 2008-06-11 15:09:02 UTC (rev 13199) @@ -295,6 +295,18 @@ </div> </div> +<h2>{tr}Export CSV data{/tr}</h2> +<form action="tiki-admin_menu_options.php" method="post"> +<input type="hidden" name="menuId" value="{$menuId}" /> +<input type="submit" name="export" value="{tr}Export{/tr}" /> +</form + +<h2>{tr}Import CSV data{/tr}</h2> +<form action="tiki-admin_menu_options.php" method="post" enctype="multipart/form-data"> +<input type="hidden" name="menuId" value="{$menuId}" /> +{tr}File{/tr}: <input name="csvfile" type="file" /> +<input type="submit" name="import" value="{tr}Import{/tr}" /> +</form> {* <form action="tiki-admin_menu_options.php" method="post"> <textarea name="menudump" cols="70" rows="42">{$menudump}</textarea><br /> Modified: branches/1.10/tiki-admin_menu_options.php =================================================================== --- branches/1.10/tiki-admin_menu_options.php 2008-06-11 14:53:48 UTC (rev 13198) +++ branches/1.10/tiki-admin_menu_options.php 2008-06-11 15:09:02 UTC (rev 13199) @@ -24,7 +24,54 @@ $smarty->display("error.tpl"); die; } +function importOptions() { + global $smarty, $menulib; + $fname = $_FILES['csvfile']['tmp_name']; + $fhandle = fopen($fname, "r"); + $fields = fgetcsv($fhandle, 1000); + if (!$fields[0]) { + $smarty->assign('msg', tra('The file is not a CSV file or has not a correct syntax')); + $smarty->display("error.tpl"); + die; + } + while (!feof($fhandle)) { + $res = array('type'=>'','name'=>'','url'=>'', 'position'=>0, 'section'=>'', 'perm'=>'', 'groupname'=>'', 'userlevel'=>''); + $data = fgetcsv($fhandle, 1000); + if (empty($data)) + continue; + for ($i = 0; $i < count($fields); $i++) { + $res[$fields[$i]] = $data[$i]; + } + $menulib->replace_menu_option($_REQUEST['menuId'], 0, $res['name'], $res['url'], $res['type'], $res['position'], $res['section'], $res['perm'], $res['groupname'], $res['userlevel']); + } +} +if (!empty($_REQUEST['import']) && !empty($_FILES['csvfile']['tmp_name'])) { + importOptions(); +} +function exportOptions() { + global $menulib; + $data = "type,name,url,position,section,perm,groupname,userlevel\r\n"; + $options = $menulib->list_menu_options($_REQUEST['menuId']); + foreach ($options['data'] as $option) { + $data .= $option['type'].',"'.str_replace('"', '""',$option['name']).'",'.str_replace('"', '""',$option['url']).','.$option['position'].','.$option['section'].','.$option['perm'].','.$option['groupname'].$option['userlevel']."\r\n"; + } + if (empty($_REQUEST['encoding'])) { + $_REQUEST['encoding'] = 'UTF-8'; + } elseif ($_REQUEST['encoding'] == 'ISO-8859-1') { + $data = utf8_decode($data); + } + header("Content-type: text/comma-separated-values; charset:".$_REQUEST['encoding']); + header("Content-Disposition: attachment; filename=".tra('menu')."_".$_REQUEST['menuId'].".csv"); + header("Expires: 0"); + header("Cache-Control: must-revalidate, post-check=0,pre-check=0"); + header("Pragma: public"); + echo $data; + die; +} +if (!empty($_REQUEST['export'])) { + exportOptions(); +} $maxPos = $menulib->get_max_option($_REQUEST["menuId"]); $smarty->assign('menuId', $_REQUEST["menuId"]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |