HuyPV
Thursday, December 24, 2009
<?php
$lines = file('menu.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$id = 1;
$parentId = 0;
$table = 'menu';
$perm_table = 'group_menu';
echo "TRUNCATE $table;\n";
echo "TRUNCATE $perm_table;\n";
foreach ($lines as $line) {
if ($line[0] != '-') {
$parentId = 0;
$arr = explode(",", $line, 3);
$num = count($arr);
$title = $arr[0];
$url = $arr[1];
$modules = isset($arr[2]) ? $arr[2] : '';
$sql = "INSERT INTO $table SET id=$id, title='$title', url='$url', parent_id='$parentId', modules='$modules';";
echo $sql . "\n";
$parentId = $id;
} else {
$line = substr($line, 2);
$arr = explode(",", $line, 3);
$num = count($arr);
$title = $arr[0];
$url = $arr[1];
$modules = isset($arr[2]) ? $arr[2] : '';
$sql = "INSERT INTO $table SET id=$id, title='$title', url='$url', parent_id='$parentId', modules='$modules';";
echo $sql . "\n";
}
$id++;
}
?>
Title:
Build menu for group
Description:
<?php $lines = file('menu.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $id = 1; $parentId = 0; $table = 'menu'; ...
...
Rating:
4