set('current_theme_path', $current_theme_path); $page->set('base_url', $base_url); //if($_POST) {p($_POST);} //header of choose content page $header = & new Template(CURRENT_THEME_FSPATH."/header.tpl"); if ($network_info) { $header->set_object('network_info', $network_info); } $header->set('current_theme_path', $current_theme_path); $header->set('onload', $onload); $header->tier_one_tab = $main_tier; $header->tier_two_tab = $second_tier; $header->tier_three_tab = $third_tier; //echo '
';print_r($_POST);
if($_POST) {
filter_all_post(&$_POST);
}
//p($_POST);
if($_POST['link_categories']) {
$tmp_array = explode(':', $_POST['link_categories']);
$_POST['category_id'] = $tmp_array[0];
}
if($_POST['btn_apply_name']) {
if($_POST['form_action'] == "update") {
if(!empty($_POST['category_name'])) { // updating a category name.
try {
$Links = new Links();
//$tmp_array = explode(':', $_POST['link_categories']);
$_POST['category_id'] = $tmp_array[0];
$param_array = array('category_name'=>$_POST['category_name'], 'category_id'=>$tmp_array[0], 'changed'=>time(), 'user_id'=> $_SESSION['user']['id']);
$Links->set_params($param_array);
$Links->update_category ();
$error_array[] = "Category updated successfully";
} catch (PAException $e) {
$error_array[] = $e->message;
}
} else {
$error_array[] = "Please select a category";
}
} else { // adding new category.
if(empty($_POST['category_name'])) {
$error_array[] = "Please enter a category name";
} else if(!Validation::validate_alpha_numeric($_POST['category_name'], 1)) {
$error_array[] = "Please enter a valid category name";
} else if(!empty($_POST['category_name'])) {
try {
$Links = new Links();
$param_array = array('user_id'=>$_SESSION['user']['id'], 'category_name'=> $_POST['category_name'], 'created'=> time(), 'changed'=> time());
$Links->set_params ($param_array);
$Links->save_category ();
$error_array[] = "Category added successfully";
} catch (PAException $e) {
$error_array[] = $e->message;
}
}
}
} else if($_POST['btn_save_link']) {
//p($_POST);
if(empty($_POST['link_categories'])) {
$error_array[] = "Please select a category";
}
if(empty($_POST['title'])) {
$error_array[] = "Please enter a title for the link";
}
if(empty($_POST['url'])) {
$error_array[] = "Please enter the URL for the link";
}
$_POST['url'] = validate_url ($_POST['url']);
if(count($error_array) == 0) {
//$tmp_array = explode(':', $_POST['link_categories']);
//$_POST['category_id'] = $tmp_array[0];
try {
if($_POST['form_action'] == "update") {
$id_array = $_POST['link_id'];
$temp = explode(':', $id_array[0]);
$link_id = $temp[1];
$param_array = array('user_id'=> $_SESSION['user']['id'], 'category_id'=> $tmp_array[0], 'title'=> $_POST['title'], 'url'=> $_POST['url'], 'changed'=> time(), 'link_id'=> $link_id);
$Links = new Links();
$Links->set_params ($param_array);
$Links->update_link ();
unset($_POST['title']);
unset($_POST['url']);
$error_array[] = 'Link updated successfully';
} else {
$param_array = array('user_id'=> $_SESSION['user']['id'], 'category_id'=> $tmp_array[0], 'title'=> $_POST['title'], 'url'=> $_POST['url'], 'changed'=> time(), 'created'=> time());
//p($param_array);
$Links = new Links();
$Links->set_params ($param_array);
$Links->save_link ();
unset($_POST['title']);
unset($_POST['url']);
$error_array[] = 'Link added successfully';
}
} catch (PAException $e) {
$error_array[] = $e->message;
}
}
} else if($_POST['form_action'] == "delete" && count($_POST['link_id']) > 0) {
$link_id_array = $_POST['link_id'];
for($counter = 0; $counter < count($link_id_array); $counter++) {
$temp_array = explode(':', $link_id_array[$counter]);
$link_ids[] = $temp_array[1];
}
$link_id_string = substr($link_id_string, 0, strlen($link_id_string) - 2);
$Links = new Links();
$param_array = array('user_id'=> $_SESSION['user']['id'], 'changed'=> time(), 'link_id'=> $link_ids);
$Links->set_params($param_array);
try {
$Links->delete_link();
$error_array[] = "Links deleted successfully";
} catch (PAException $e) {
$error_array[] = $e->message;
}
} else if($_POST['form_action'] == "delete" && !empty($_POST['link_categories'])) {
$param_array = array('user_id'=> $_SESSION['user']['id'], 'category_id'=> $_POST['category_id'], 'changed'=> time());
$Links = new Links();
$Links->set_params ($param_array);
try {
$Links->delete_category();
$error_array[] = "Category deleted successfully";
} catch (PAException $e) {
$error_array[] = $e->message;
}
}
//left modules
foreach ( $leftModulesFromDB as $leftModule)
{
$file = "BlockModules/$leftModule/$leftModule.php";
require_once $file;
$obj = new $leftModule;
$array_left_modules[] = $obj->render();
}
//error displaying
if (count($error_array) > 0) {
for($counter = 0; $counter < count($error_array); $counter++) {
$message .= $error_array[$counter]."
";
}
$msg_tpl = & new Template(CURRENT_THEME_FSPATH."/display_message.tpl");
$msg_tpl->set('message', $message);
$array_middle_modules[] = $msg_tpl->fetch();
}
//middle modules
foreach ( $middleModulesFromDB as $middleModule)
{
$file = "BlockModules/$middleModule/$middleModule.php";
require_once $file;
$obj = new $middleModule;
$obj->get_link_categories ();
$array_middle_modules[] = $obj->render();
}
//right modules
foreach ( $rightModulesFromDB as $rightModule)
{
$file = "BlockModules/$rightModule/$rightModule.php";
require_once $file;
$obj = new $rightModule;
$array_right_modules[] = $obj->render();
}
$footer = & new Template(CURRENT_THEME_FSPATH."/footer.tpl");
$footer->set('current_theme_path', $current_theme_path);
//page settings
$page->set('header', $header);
$page->set('array_left_modules', $array_left_modules);
$page->set('array_middle_modules', $array_middle_modules);
$page->set('array_right_modules', $array_right_modules);
$page->set('footer', $footer);
$page->set('current_theme_path', $current_theme_path);
echo $page->fetch();
?>