$json_string = '{ "is_error" : true, "errors" : "' . $e->message . '"}'; } print $json_string; /** * Creating a new link under the list */ } else { if (!empty($_POST) && $_POST['form_action'] == 'create_link') { //TODO: check for empty fields $Links = new Links(); $Links->user_id = $_SESSION['user']['id']; $Links->category_id = $_POST['category_id']; $Links->title = $_POST['title']; $Links->url = Validation::validate_url($_POST['url']); try { $Links->save_link(); $json_string = '{ "errors" : "Link has been added successfully", "updated_category_id" : ' . $_POST['category_id'] . '}'; } catch (PAException $e) { $json_string = '{ "is_error" : true, "errors" : "' . $e->message . '"}'; } print $json_string; } else { if (!empty($_POST) && $_POST['form_action'] == 'remove_list') { $Links = new Links(); $Links->user_id = $_SESSION['user']['id']; $Links->category_id = $_POST['category_id']; try { $Links->delete_category(true); $json_string = '{ "errors" : "List has been deleted successfully"}'; } catch (PAException $e) { $json_string = '{ "is_error" : true, "errors" : "' . $e->message . '"}';
public static function add_default_links($user_id) { require_once "api/CNNetworkLinks/CNNetworkLinks.php"; require_once "api/CNLinks/CNLinks.php"; $network_links = new NetworkLinks(); $network_owner_id = PA::$network_info->type == MOTHER_NETWORK_TYPE ? SUPER_USER_ID : Network::get_network_owner(PA::$network_info->network_id); $condition = array('user_id' => $network_owner_id, 'is_active' => 1); $link_categories = $network_links->load_category($condition); // load category as set by network operator $Links = new Links(); $error_array = array(); //providing default links to the user, as set by network operator for ($counter = 0; $counter < count($link_categories); $counter++) { $param_array = array('category_name' => $link_categories[$counter]->category_name, 'user_id' => $user_id, 'created' => time(), 'changed' => time(), 'is_active' => ACTIVE); $Links->set_params($param_array); $category_id = $Links->save_category(); // save network operator category as user's link category $network_lists = new NetworkLinks(); $network_lists->user_id = $network_info->owner_id; $condition = array('category_id' => $link_categories[$counter]->category_id, 'is_active' => ACTIVE); $list_array = $network_lists->load_link($condition); // load list for network operator's category for ($i = 0; $i < count($list_array); $i++) { $param_array = array('title' => $list_array[$i]->title, 'url' => $list_array[$i]->url, 'category_id' => $category_id, 'created' => time(), 'changed' => time(), 'is_active' => ACTIVE); $Links->set_params($param_array); $Links->save_link(); // save network operator list as user's list } } }