public function handlePOST($request_data)
 {
     global $mothership_info;
     if (!empty($request_data['request'])) {
         //code for requesting
         $this->error = FALSE;
         $this->success = FALSE;
         try {
             $request_sent = Network::join(PA::$network_info->network_id, PA::$login_uid);
             if (!empty($request_sent)) {
                 $this->success = TRUE;
             }
         } catch (PAException $e) {
             $join_error = $e->message;
             $this->error = TRUE;
         }
         if (!empty($this->error)) {
             $this->error_msg = sprintf(__('Your request to join this network could not be sent due to following reason: %s. You can go back to the home network by clicking Return to home network'), $join_error);
         } else {
             $this->success_msg = __('Your request to join this network has been successfully sent to the moderator of this network. The Moderator will check this request and approve or deny the request. You can go back to mother network by clicking the button Return to home network');
         }
         $this->mode = 'msg_display';
     }
     if (!empty($request_data['back'])) {
         //redirect to mother network
         global $mothership_info;
         $this->message = __('Return to home network successfully.');
         $this->redirect2 = NULL;
         $his->queryString = NULL;
         $this->isError = FALSE;
         $this->setWebPageMessage();
     }
 }
                User_Registration::add_default_links($newuser->user_id);
                // code for adding default desktop image for user
                $desk_img = uihelper_add_default_desktopimage($newuser->user_id);
                if (empty($desk_img)) {
                    $desktop_images = array('bay.jpg', 'everglade.jpg', 'bay_boat.jpg', 'delhi.jpg');
                    $rand_key = array_rand($desktop_images);
                    $desk_img = $desktop_images[$rand_key];
                }
                $data_array = array(0 => array('uid' => $newuser->user_id, 'name' => 'user_caption_image', 'value' => $desk_img, 'type' => GENERAL, 'perm' => 1));
                $newuser->save_user_profile($data_array, GENERAL);
                //sending mail to the newly created user
                $msg = "User has been Added successfully";
                //if new user is created in a network then he must set as a joined user
                if (!empty(PA::$network_info)) {
                    $by_admin = true;
                    Network::join(PA::$network_info->network_id, $newuser->user_id, NETWORK_MEMBER, $by_admin);
                    // $by_admin = true overrides the
                    // user_waiting status if it would get set
                    // this is an admin action, so we want it to happen in any case
                }
                $form_data = array();
            } catch (CNException $e) {
                $msg = $e->message;
            }
        }
        // end if
    }
    //end if
}
//main if
function setup_module($column, $module, $obj)
 function register($params, $network_info = NULL)
 {
     $core_id = null;
     $picture = null;
     $picture_dimensions = null;
     $avatar = null;
     $avatar_dimensions = null;
     $avatar_small = null;
     $avatar_small_dimensions = null;
     $this->newuser = new User();
     // set API call variable
     $this->newuser->api_call = $this->api_call;
     // filter input parameters (this is the same as filter_all_post())
     $params = Validation::get_input_filter(FALSE)->process($params);
     $this->error = false;
     $mother_network_info = Network::get_mothership_info();
     $mother_extra = unserialize($mother_network_info->extra);
     if (@$mother_extra['captcha_required'] == NET_YES) {
         // added by Z.Hron - if captcha is required
         //Providing the capcha check
         if (md5(strtoupper($_POST['txtNumber'])) != $_SESSION['image_random_value']) {
             $_SESSION['image_is_logged_in'] = true;
             $_SESSION['image_random_value'] = '';
             $error_login = true;
             $this->error = true;
             $this->msg .= "\nPlease enter correct code";
         }
     }
     if (!$this->error) {
         $login_name = trim($params['login_name']);
         $first_name = trim($params['first_name']);
         $last_name = trim(@$params['last_name']);
         // not mandatory
         $email = trim($params['email']);
         $password = trim($params['password']);
         $confirm_password = trim($params['confirm_password']);
         if ($this->api_call == true) {
             $core_id = $params['core_id'];
             // TODO: validate URL
             $picture = trim($params['profile_picture_url']);
             $picture_dimensions = $params['profile_picture_dimensions'];
             $avatar = trim($params['profile_avatar_url']);
             $avatar_dimensions = $params['profile_avatar_dimensions'];
             $avatar_small = trim($params['profile_avatar_small_url']);
             $avatar_small_dimensions = $params['profile_avatar_small_dimensions'];
         }
         $date_created = !empty($params['date_created']) ? $params['date_created'] : null;
         $_years = PA::getYearsList();
         $dob_day = !empty($params['dob_day']) ? trim($params['dob_day']) : null;
         // General data (why? should be personal)
         $dob_month = !empty($params['dob_month']) ? trim($params['dob_month']) : null;
         // General data (why? should be personal)
         $dob_year = !empty($params['dob_year']) ? $_years[(int) trim($params['dob_year'])] : null;
         // General data (why? should be personal)
         $homeAddress1 = !empty($params['homeAddress1']) ? trim($params['homeAddress1']) : null;
         // General data
         $homeAddress2 = !empty($params['homeAddress2']) ? trim($params['homeAddress2']) : null;
         // General data
         $city = !empty($params['city']) ? trim($params['city']) : null;
         // General data
         $state = null;
         if ($params['state'] == -1) {
             // State/Province: Other selected
             $state = !empty($params['stateOther']) ? trim($params['stateOther']) : null;
             // General data
         } else {
             if ($params['state'] > 0) {
                 // one of US States selected
                 $state = !empty($params['state']) ? $this->states[(int) $params['state']] : null;
                 // General data
             }
         }
         $country = $params['country'] > 0 ? $this->countries[(int) $params['country']] : null;
         // General data
         $postal_code = !empty($params['postal_code']) ? trim($params['postal_code']) : null;
         // General data
         $phone = !empty($params['phone']) ? trim($params['phone']) : null;
         // General data
         $validate_array = array('login_name' => 'Login name', 'first_name' => 'First name', 'password' => 'Password', 'confirm_password' => 'Confirm password', 'email' => 'Email');
         $this->msg = '';
         $this->error = FALSE;
         foreach ($validate_array as $key => $value) {
             if (empty($params[$key])) {
                 $this->msg .= "\n" . $value . " is mandatory";
                 $this->error = TRUE;
                 header(HttpStatusCodes::httpHeaderFor(HttpStatusCodes::HTTP_PRECONDITION_FAILED));
             }
         }
         if (strlen($this->msg) > 0) {
             $this->msg = "\n" . "Fields marked with * must not be left empty" . $this->msg;
         }
     }
     //$error_login = FALSE;
     if (!$this->error) {
         if (empty($login_name)) {
             $error_login = TRUE;
             $this->error = TRUE;
         }
         if (is_numeric($login_name)) {
             // Here we check the login name  is numeric or not
             if (strlen($this->msg) > 0) {
                 $this->msg .= "\n";
             }
             $this->msg .= "Login name must not be numeric";
             $error_login = TRUE;
             $this->error = TRUE;
         }
         if (is_numeric($first_name)) {
             // Here we check the first  name  is numeric or not
             if (strlen($this->msg) > 0) {
                 $this->msg .= "\n";
             }
             $this->msg .= "First name must not be numeric";
             $error_login = TRUE;
             $this->error = TRUE;
         }
         if (is_numeric($last_name)) {
             // Here we check the last name  is numeric or not
             if (strlen($this->msg) > 0) {
                 $this->msg .= "\n";
             }
             $this->msg .= "Last name must not be numeric";
             $error_login = TRUE;
             $this->error = TRUE;
         }
         if ($this->error == TRUE) {
             header(HttpStatusCodes::httpHeaderFor(HttpStatusCodes::HTTP_PRECONDITION_FAILED));
         }
     }
     // if error occur than no need to check these errors
     if (!$this->error) {
         if (!Validation::validate_email($email)) {
             $email_invalid = TRUE;
             $this->array_of_errors['error_email'] = $email_invalid;
             $this->error = TRUE;
             $this->msg .= __('E-mail address is not valid.');
             header(HttpStatusCodes::httpHeaderFor(HttpStatusCodes::HTTP_PRECONDITION_FAILED));
         }
         // Calculating Allowed Domains
         if (file_exists(PA::$project_dir . "/config/domain_names.txt")) {
             $domain_names_file = PA::$project_dir . "/config/domain_names.txt";
         } elseif (file_exists(PA::$core_dir . "/config/domain_names.txt")) {
             $domain_names_file = PA::$core_dir . "/config/domain_names.txt";
         } else {
             throw new Exception("Allowed Domains configuration file \"/config/domain_names.txt\" not found");
         }
         $allowed_domains = preg_split("/\\s+/", file_get_contents($domain_names_file));
         // Calcutating user domain
         $user_email = explode('@', $email);
         $user_domain = strtolower($user_email[1]);
         $found = 0;
         foreach ($allowed_domains as $i => $d) {
             if (!preg_match('/\\W/', $d)) {
                 continue;
             }
             // make proper regex
             $rx = preg_replace('/\\*/', '[^\\.]*', $d);
             if (preg_match("/{$rx}/", $user_domain)) {
                 $found++;
             }
         }
         if (!$found) {
             // show error
             $email_invalid = TRUE;
             $this->array_of_errors['error_email'] = $email_invalid;
             $this->error = TRUE;
             $this->msg .= __('The domain of your E-mail address is not in the list of allowed domains.');
             header(HttpStatusCodes::httpHeaderFor(HttpStatusCodes::HTTP_PRECONDITION_FAILED));
         }
         if ($password != $confirm_password) {
             $this->msg .= "\nPassword and Confirm Password do not match.";
             $error_password_conf = TRUE;
             $this->error = TRUE;
         }
         if ($this->api_call == true) {
             // dont check maximum password length if this is an API call
             // this is so that the API call can accept an encrypted password
         } else {
             // this is not an API request, so check password length normally
             if (strlen($password) > PA::$password_max_length) {
                 $this->msg .= sprintf(__("\nThe password must be less than %d characters."), PA::$password_max_length);
                 $error_password_l = TRUE;
                 $this->error = TRUE;
                 header(HttpStatusCodes::httpHeaderFor(HttpStatusCodes::HTTP_PRECONDITION_FAILED));
             }
         }
         if (strlen($password) < PA::$password_min_length) {
             $this->msg .= sprintf(__("\nThe password must be longer than %d characters."), PA::$password_min_length);
             $error_password_g = TRUE;
             $this->error = TRUE;
             header(HttpStatusCodes::httpHeaderFor(HttpStatusCodes::HTTP_PRECONDITION_FAILED));
         }
     }
     if (!$this->error) {
         if (User::user_exist($login_name)) {
             $this->msg = "Login name {$login_name} is already taken";
             $error_login = TRUE;
             $this->error = TRUE;
             header(HttpStatusCodes::httpHeaderFor(HttpStatusCodes::HTTP_CONFLICT));
         } elseif (User::user_existed($login_name)) {
             $this->msg = "Login name {$login_name} has been used in the past; it belongs to a deleted user.";
             $error_login = $this->error = TRUE;
             header(HttpStatusCodes::httpHeaderFor(HttpStatusCodes::HTTP_CONFLICT));
         }
         $this->array_of_errors = array("error_login" => @$error_login, "error_first_name" => @$error_first_name, "error_email" => @$error_email, "error_password_conf" => @$error_password_conf, "error_password_l" => @$error_password_l, "error_password_g" => @$error_password_g);
     }
     if ($this->error != TRUE) {
         $this->newuser->login_name = $login_name;
         //TODO: change to md5
         $this->newuser->password = $password;
         $this->newuser->first_name = $first_name;
         $this->newuser->last_name = $last_name;
         $this->newuser->email = $email;
         if ($date_created) {
             // for users inserted via import accounts script!
             $this->newuser->created = $date_created;
         }
         if ($this->api_call == true) {
             $this->newuser->core_id = $core_id;
             if ($picture != null && $picture != '') {
                 $this->newuser->picture = $picture;
                 $this->newuser->picture_dimensions = $picture_dimensions;
             } else {
                 $this->newuser->picture_dimensions = User::image_dimensions_to_array(0, 0);
             }
             if ($avatar != null && $avatar != '') {
                 $this->newuser->avatar = $avatar;
                 $this->newuser->avatar_dimensions = $avatar_dimensions;
             } else {
                 $this->newuser->avatar_dimensions = User::image_dimensions_to_array(0, 0);
             }
             if ($avatar_small != null && $avatar_small != '') {
                 $this->newuser->avatar_small = $avatar_small;
                 $this->newuser->avatar_small_dimensions = $avatar_small_dimensions;
             } else {
                 $this->newuser->avatar_small_dimensions = User::image_dimensions_to_array(0, 0);
             }
         } else {
             $this->newuser->picture = Storage::validateFileId(@$params['user_filename']);
         }
     }
     if ($this->error != TRUE) {
         try {
             $save_error = FALSE;
             $extra = unserialize($network_info->extra);
             if ($mother_extra['email_validation'] == NET_NO || $this->api_call == true) {
                 // if email validation not required
                 $this->newuser->is_active = ACTIVE;
             } else {
                 $this->newuser->is_active = UNVERIFIED;
             }
             $this->newuser->save();
             if ($this->newuser->picture) {
                 Storage::link($this->newuser->picture, array("role" => "avatar", "user" => $this->newuser->user_id));
             }
             /* The following code should now be obsolete as this is done in User->save() */
             // saving data in user profile data also -- for searching making more easier
             $data_array = array(array('uid' => $this->newuser->user_id, 'name' => 'first_name', 'value' => $this->newuser->first_name, 'type' => BASIC, 'perm' => 1), array('uid' => $this->newuser->user_id, 'name' => 'last_name', 'value' => $this->newuser->last_name, 'type' => BASIC, 'perm' => 1));
             $this->newuser->save_user_profile($data_array, BASIC);
             // saving default notification for user from network notification setting
             $user_notification = array();
             $profile = array();
             $user_notification = $extra['notify_members'];
             $user_notification['msg_waiting_blink'] = $extra['msg_waiting_blink'];
             $profile['settings']['name'] = 'settings';
             $profile['settings']['value'] = serialize($user_notification);
             $this->newuser->save_profile_section($profile, 'notifications');
             // default notification for user ends
             $desktop_images = User_Registration::get_default_desktopimage($this->newuser->user_id, $network_info);
             // code for adding default desktop image for user
             if ($desktop_images == "") {
                 $desktop_images = array('bay.jpg', 'everglade.jpg', 'bay_boat.jpg', 'delhi.jpg');
                 $rand_key = array_rand($desktop_images);
                 $desk_img = $desktop_images[$rand_key];
             } else {
                 $desk_img = $desktop_images;
             }
             $data_array = array(0 => array('uid' => $this->newuser->user_id, 'name' => 'user_caption_image', 'value' => $desk_img, 'type' => GENERAL, 'perm' => NONE), 1 => array('uid' => $this->newuser->user_id, 'name' => 'dob_day', 'value' => $dob_day, 'type' => GENERAL, 'perm' => NONE), 2 => array('uid' => $this->newuser->user_id, 'name' => 'dob_month', 'value' => $dob_month, 'type' => GENERAL, 'perm' => NONE), 3 => array('uid' => $this->newuser->user_id, 'name' => 'dob_year', 'value' => $dob_year, 'type' => GENERAL, 'perm' => NONE), 4 => array('uid' => $this->newuser->user_id, 'name' => 'dob', 'value' => $dob_year . '-' . $dob_month . '-' . $dob_day, 'type' => GENERAL, 'perm' => NONE), 5 => array('uid' => $this->newuser->user_id, 'name' => 'homeAddress1', 'value' => $homeAddress1, 'type' => GENERAL, 'perm' => NONE), 6 => array('uid' => $this->newuser->user_id, 'name' => 'homeAddress2', 'value' => $homeAddress2, 'type' => GENERAL, 'perm' => NONE), 7 => array('uid' => $this->newuser->user_id, 'name' => 'city', 'value' => $city, 'type' => GENERAL, 'perm' => NONE), 8 => array('uid' => $this->newuser->user_id, 'name' => 'state', 'value' => $state, 'type' => GENERAL, 'perm' => NONE), 9 => array('uid' => $this->newuser->user_id, 'name' => 'country', 'value' => $country, 'type' => GENERAL, 'perm' => NONE), 10 => array('uid' => $this->newuser->user_id, 'name' => 'postal_code', 'value' => $postal_code, 'type' => GENERAL, 'perm' => NONE), 11 => array('uid' => $this->newuser->user_id, 'name' => 'phone', 'value' => $phone, 'type' => GENERAL, 'perm' => NONE));
             //}
             $this->newuser->save_user_profile($data_array, GENERAL);
             if ($mother_extra['email_validation'] == NET_NO || $this->api_call == true) {
                 //if email validation is not required
                 // creating message basic folders
                 Message::create_basic_folders($this->newuser->user_id);
                 // adding default relation
                 if ($this->newuser->user_id != SUPER_USER_ID) {
                     User_Registration::add_default_relation($this->newuser->user_id, $network_info);
                 }
                 // adding default media as well as album
                 User_Registration::add_default_media($this->newuser->user_id, '', $network_info);
                 User_Registration::add_default_media($this->newuser->user_id, '_audio', $network_info);
                 User_Registration::add_default_media($this->newuser->user_id, '_video', $network_info);
                 User_Registration::add_default_blog($this->newuser->user_id);
                 //adding default link categories & links
                 User_Registration::add_default_links($this->newuser->user_id);
                 // adding header image
                 User_Registration::add_default_header($this->newuser->user_id);
                 // Making user member of a network if he is registering to PA from a network
                 if (!empty($network_info) && $network_info->type != PRIVATE_NETWORK_TYPE) {
                     $user_type = null;
                     $register_by_admin = false;
                     if ($this->api_call == true) {
                         // since this is an API call, default this member as a
                         // NETWORK_MEMBER since they already registered
                         $user_type = NETWORK_MEMBER;
                         // since this is an API call, act like it is registration by admin
                         $register_by_admin = true;
                     }
                     Network::join($network_info->network_id, $this->newuser->user_id, $user_type, $register_by_admin);
                     if ($this->api_call == false) {
                         // only send notification of network if this is NOT an API call
                         PANotify::send("network_join", $network_info, $this->newuser, array());
                     }
                 }
             }
         } catch (CNException $e) {
             $this->msg = $e->message;
             if ($e->code == USER_EMAIL_NOT_UNIQUE) {
                 $this->msg = "Email Address has already been taken, please enter other email address.";
             }
             $save_error = TRUE;
             if ($e->message == "The email address is invalid.") {
                 $email_invalid = TRUE;
                 $this->array_of_errors['error_email'] = $email_invalid;
             }
         }
     }
     if ($this->error == TRUE || $save_error == TRUE) {
         $this->msg = "Sorry! your registration failed. " . $this->msg;
         return FALSE;
     }
     // success!
     // give Login User permissions to new user is moved to  Network::join() now!
     /*
      $this->newuser->set_user_role(array(LOGINUSER_ROLE));
     */
     return TRUE;
 }
            try {
                $new_invite = new Invitation();
                $new_invite->inv_id = $invitation_id;
                $new_invite->inv_user_id = $_SESSION['user']['id'];
                $new_invite->accept();
                $inv_obj = Invitation::load($invitation_id);
                $user_obj = new User();
                $user_obj->load((int) $inv_obj->user_id);
                $user_accepting_inv_obj = new User();
                $user_accepting_inv_obj->load((int) $_SESSION['user']['id']);
                $relation_type_id = Relation::get_relation((int) $inv_obj->user_id, (int) $user_accepting_inv_obj->user_id, PA::$network_info->network_id);
                $relation_type = Relation::lookup_relation_type($relation_type_id);
                $new_invite->inv_relation_type = $relation_type;
                PANotify::send("invitation_accept", $user_obj, $user_accepting_inv_obj, $new_invite);
                if (!Network::member_exists(PA::$network_info->network_id, (int) $_SESSION['user']['id'])) {
                    Network::join(PA::$network_info->network_id, $_SESSION['user']['id']);
                    PANotify::send("network_join", PA::$network_info, $user_accepting_inv_obj, array());
                }
                header("Location: " . PA::$url . PA_ROUTE_USER_PRIVATE . '/' . "msg_id=7016");
                exit;
            } catch (CNException $e) {
                $msg = $e->message;
            }
        }
    } else {
        $msg = $token_arr[0] == FALSE ? $token_arr[1] : 7018;
        header("Location: " . PA_ROUTE_HOME_PAGE . "/msg={$msg}");
        exit;
    }
}
$ConfigurableText = new ConfigurableText();
require_once "api/Roles/Roles.php";
if ($_GET['action'] == 'join') {
    $nid = (int) $_GET['nid'];
    // here we check that user is already join or not
    if ($_SESSION['user']['id'] && Network::member_exists($nid, $_SESSION['user']['id'])) {
        $redirect_url = "http://" . PA::$network_info->address . "." . PA::$domain_suffix . BASE_URL_REL . PA_ROUTE_HOME_PAGE . "/msg=7021";
        header("Location:{$redirect_url}");
        exit;
    }
    $error = 0;
    if (!$nid) {
        $error = 1;
    }
    if ($_SESSION['user']['id']) {
        try {
            $suc = Network::join($nid, $_SESSION['user']['id']);
            if ($suc) {
                // adding default relation
                if ($_SESSION['user']['id'] != SUPER_USER_ID) {
                    uihelper_add_default_relation($_SESSION['user']['id']);
                }
                // adding default media as well as album
                uihelper_add_default_media($_SESSION['user']['id']);
                uihelper_add_default_media($_SESSION['user']['id'], '_audio');
                uihelper_add_default_media($_SESSION['user']['id'], '_video');
                uihelper_add_default_blog($_SESSION['user']['id']);
            }
        } catch (PAException $e) {
            $msg = "{$e->message}";
        }
        $network = new Network();
 // creating message basic folders
 Message::create_basic_folders($newuser->user_id);
 // adding default relation
 if ($newuser->user_id != SUPER_USER_ID) {
     User_Registration::add_default_relation($newuser->user_id, $network_info);
 }
 // adding default media as well as album
 User_Registration::add_default_media($newuser->user_id, '', $network_info);
 User_Registration::add_default_media($newuser->user_id, '_audio', $network_info);
 User_Registration::add_default_media($newuser->user_id, '_video', $network_info);
 User_Registration::add_default_blog($newuser->user_id);
 //adding default link categories & links
 User_Registration::add_default_links($newuser->user_id);
 // Making user member of a network if he is registering to PA from a network
 if (!empty($network_info)) {
     Network::join($network_info->network_id, $newuser->user_id);
 }
 // register session
 register_session($newuser->login_name, $newuser->user_id, $newuser->role, $newuser->first_name, $newuser->last_name, $newuser->email, $newuser->picture);
 if (!empty($_GET['InvID'])) {
     // if network invitation
     $invitation_id = $_GET['InvID'];
     $inv_error = "";
     $error_inv = false;
     try {
         $is_valid = Invitation::validate_invitation_id($invitation_id);
         if (!$is_valid) {
             throw new PAException(INVALID_INV, "Sorry but the invitation ID you are using is no longer valid.");
         }
         $new_invite = new Invitation();
         $new_invite->inv_id = $invitation_id;
 function testNetworkCreation()
 {
     // check that we can create networks
     $can = Network::can_network_be_created();
     $this->assertFalse($can['error'], $can['error_msg']);
     // get network owner user and figure out name etc
     $user = Test::get_test_user();
     $name = "testnet" . rand(10000, 99999);
     $network_basic_controls = array();
     // with crossed fingers, we hope that it will succeed without any of the detail here!
     // make a new network
     $net = new Network();
     $net->set_params(array('user_id' => $user->user_id, 'name' => "auto-test network ({$name})", 'address' => $name, 'tagline' => "not much of a tagline", 'category_id' => 8, 'type' => 0, 'description' => "This network has been created automatically by a PHPUnit test.  If the test succeeds, it will be deleted, too!", 'extra' => serialize($network_basic_controls), 'created' => time(), 'changed' => time()));
     $net->save();
     //default_page_setting($net->address);
     // read it in again and see if it still works
     $net_read = Network::get_network_by_address($net->address);
     $this->assertEquals($net_read->network_id, $net->network_id);
     $this->assertEquals($net_read->type, 0);
     $this->assertEquals($net_read->member_count, 1);
     $this->assertEquals($net_read->owner_id, $user->user_id);
     // a user joins
     $user2 = Test::get_test_user(2);
     Network::join($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 2);
     // a user leaves
     Network::leave($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 1);
     // make it into a moderated network
     $net->type = 2;
     $net->save();
     // check that it really is moderated
     $net_read = Network::get_network_by_address($net->address);
     $this->assertEquals($net_read->network_id, $net->network_id);
     $this->assertEquals($net_read->type, 2);
     // a user requests
     Network::join($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 1);
     // request approved
     Network::approve($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 2);
     // user leaves
     Network::leave($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 1);
     // user requests
     Network::join($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 1);
     // all requests accepted (of course, there will only be the one)
     Network::approve_all($net->network_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 2);
     // user leaves
     Network::leave($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 1);
     // user requests
     Network::join($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 1);
     // request denied
     Network::deny($net->network_id, $user2->user_id);
     $this->assertEquals(Network::get_network_by_address($net->address)->member_count, 1);
     // delete network
     Network::delete($net->network_id);
 }
     $new_invite->inv_id = $invitation_id;
     $new_invite->inv_user_id = $u;
     $new_invite->accept();
     $inv_obj = Invitation::load($invitation_id);
     $user_obj = new User();
     $user_obj->load((int) $inv_obj->user_id);
     $relation_type_id = Relation::get_relation((int) $inv_obj->user_id, (int) $user_accepting_inv_obj->user_id, PA::$network_info->network_id);
     $relation_type = Relation::lookup_relation_type($relation_type_id);
     $new_invite->inv_relation_type = $relation_type;
     PANotify::send("invitation_accept", $user_obj, $user_accepting_inv_obj, $new_invite);
     if (!empty(PA::$network_info) && PA::$network_info->type != MOTHER_NETWORK_TYPE) {
         if (!Network::member_exists(PA::$network_info->network_id, $u)) {
             if (PA::$network_info->type == PRIVATE_NETWORK_TYPE && $inv_obj->user_id == PA::$network_info->owner_id) {
                 $user_type = NETWORK_MEMBER;
             }
             Network::join(PA::$network_info->network_id, $u, $user_type);
             PANotify::send("network_join", PA::$network_info, $user_accepting_inv_obj, array());
         }
     }
 } catch (CNException $e) {
     $msg = "{$e->message}";
     $error_inv = TRUE;
 }
 if ($error_inv == TRUE) {
     // if error occured
     $location = CNUrlHelper::url_for(PA::$url . '/cnuser_login.php', array('msg' => $msg, 'return' => $return_url), 'https');
     header("Location: {$location}");
     //	  header("Location:login.php?msg=$msg&return=$return_url");
     exit;
 }
 $location = PA::$after_login_page . '/msg=7016';
                //adding default link categories & links
                User_Registration::add_default_links($newuser->user_id);
                // code for adding default desktop image for user
                $desk_img = uihelper_add_default_desktopimage($newuser->user_id);
                if (empty($desk_img)) {
                    $desktop_images = array('bay.jpg', 'everglade.jpg', 'bay_boat.jpg', 'delhi.jpg');
                    $rand_key = array_rand($desktop_images);
                    $desk_img = $desktop_images[$rand_key];
                }
                $data_array = array(0 => array('uid' => $newuser->user_id, 'name' => 'user_caption_image', 'value' => $desk_img, 'type' => GENERAL, 'perm' => 1));
                $newuser->save_user_profile($data_array, GENERAL);
                //sending mail to the newly created user
                $msg = "User has been Added successfully";
                //if new user is created in a network then he must set as a joined user
                if (!empty($network_info)) {
                    Network::join($network_info->network_id, $newuser->user_id, NETWORK_MEMBER);
                }
                $form_data = array();
            } catch (PAException $e) {
                $msg = $e->message;
            }
        }
        // end if
    }
    //end if
}
//main if
function setup_module($column, $module, $obj)
{
    global $paging, $form_data, $msg, $configure_permission;
    if (!$configure_permission) {
 function handle_join()
 {
     $error_inv = false;
     $invitation_id = isset($_REQUEST['InvID']) ? $_REQUEST['InvID'] : null;
     $group_invitation_id = isset($_REQUEST['GInvID']) ? $_REQUEST['GInvID'] : null;
     $mother_network_info = Network::get_mothership_info();
     $extra = unserialize($mother_network_info->extra);
     if (!$this->reg_user->register($_POST, PA::$network_info)) {
         // registration failed
         return;
     }
     // If the user is joining a network other than the
     if ($mother_network_info->network_id != PA::$network_info->network_id) {
         Network::join(1, $this->reg_user->newuser->user_id, NETWORK_MEMBER);
     }
     if ($extra['email_validation'] == NET_NO || $this->silent) {
         // silent registration - no email validation!
         // Success!
         if (!$this->silent) {
             register_session($this->reg_user->newuser->login_name, $this->reg_user->newuser->user_id, $this->reg_user->newuser->role, $this->reg_user->newuser->first_name, $this->reg_user->newuser->last_name, $this->reg_user->newuser->email, $this->reg_user->newuser->picture);
             $_SESSION['login_source'] = 'password';
             // password recently entered, so enable access to edit profile
             PANotify::send("new_user_registered", PA::$network_info, $this->reg_user->newuser, array());
         }
         if ($invitation_id) {
             // if an invitation to join a network
             $this->inv_error = "";
             $is_valid = Invitation::validate_invitation_id($invitation_id);
             if (!$is_valid) {
                 $msg = 7017;
                 // invalid network invitation
             }
             if (empty($msg)) {
                 try {
                     // try to except invitation
                     $new_invite = new Invitation();
                     $new_invite->inv_id = $invitation_id;
                     $new_invite->inv_user_id = $this->reg_user->newuser->user_id;
                     $new_invite->accept();
                     $inv_obj = Invitation::load($invitation_id);
                     $user_obj = new User();
                     $user_obj->load((int) $inv_obj->user_id);
                     //if invitation is for private network
                     if (PA::$network_info->type == PRIVATE_NETWORK_TYPE) {
                         $user_type = NULL;
                         if (PA::$network_info->owner_id == $inv_obj->user_id) {
                             $user_type = NETWORK_MEMBER;
                         }
                         Network::join(PA::$network_info->network_id, $this->reg_user->newuser->user_id, $user_type);
                     }
                     $msg = 7016;
                     $relation_type = null;
                     $relationship_level = 2;
                     //default relation level id is 2 for friend
                     try {
                         $relation_type_id = Relation::get_relation((int) $inv_obj->user_id, (int) $this->reg_user->newuser->user_id, PA::$network_info->network_id);
                     } catch (PAException $e) {
                         Relation::add_relation((int) $inv_obj->user_id, (int) $this->reg_user->newuser->user_id, $relationship_level, PA::$network_info->address, PA::$network_info->network_id, NULL, NULL, NULL, true, APPROVED);
                         $relation_type = Relation::lookup_relation_type($relation_type_id);
                     }
                     $new_invite->inv_relation_type = $relation_type;
                     if (!$this->silent) {
                         PANotify::send("invitation_accept", $user_obj, $this->reg_user->newuser, $new_invite);
                     }
                 } catch (PAException $e) {
                     $this->inv_error = $e->message;
                     $this->reg_user->msg = "{$e->message}";
                     $error_inv = TRUE;
                 }
                 if ($error_inv == TRUE) {
                     // if invitation fails, then do login again
                     header("Location: " . PA::$url . "/login.php?msg=" . $this->reg_user->msg . "&return={$return_url}");
                     exit;
                 }
             }
             $redirect_url = PA_ROUTE_HOME_PAGE . '/msg=' . $msg;
         } else {
             if ($group_invitation_id) {
                 // if an invitation to join a group
                 // User registration is in response to a group invitation, so
                 // now that the user is registered, handle the group invitation.
                 try {
                     $is_valid_ginv = Invitation::validate_group_invitation_id($group_invitation_id);
                     if (!$is_valid_ginv) {
                         $msg = 3001;
                     }
                 } catch (PAException $e) {
                     $this->inv_error = "{$e->message}";
                 }
                 if (empty($msg)) {
                     //if group invitation is valid, and no error yet
                     try {
                         $new_invite = new Invitation();
                         $new_invite->inv_id = $group_invitation_id;
                         $new_invite->inv_user_id = $this->reg_user->newuser->user_id;
                         $new_invite->accept();
                         //get collection_id
                         $Ginv = Invitation::load($group_invitation_id);
                         $gid = $Ginv->inv_collection_id;
                         $relationship_level = 2;
                         //default relation level id is 2 for friend
                         try {
                             $relation_type_id = Relation::get_relation((int) $Ginv->user_id, (int) $this->reg_user->newuser->user_id, PA::$network_info->network_id);
                         } catch (PAException $e) {
                             Relation::add_relation((int) $Ginv->user_id, (int) $this->reg_user->newuser->user_id, $relationship_level, PA::$network_info->address, PA::$network_info->network_id, NULL, NULL, NULL, true, APPROVED);
                             Relation::add_relation((int) $this->reg_user->newuser->user_id, (int) $Ginv->user_id, $relationship_level, PA::$network_info->address, PA::$network_info->network_id, NULL, NULL, NULL, true, APPROVED);
                         }
                     } catch (PAException $e) {
                         $this->reg_user->msg = "{$e->message}";
                         $this->reg_user->error = TRUE;
                         print $this->reg_user->msg;
                     }
                     $redirect_url = PA_ROUTE_GROUP . "/gid={$gid}&action=join&GInvID={$group_invitation_id}";
                 } else {
                     //else redirect registered user to its page.
                     $redirect_url = PA_ROUTE_USER_PRIVATE . '/' . "msg_id={$msg}";
                 }
                 // end of if group invitation is valid
             }
         }
         if (empty($redirect_url)) {
             // if no url is set yet
             // not a group invitation, so redirect to private user page when done
             $msg = 5003;
             $redirect_url = PA_ROUTE_USER_PRIVATE . '/' . "msg_id={$msg}";
         }
         header("Location: " . PA::$url . $redirect_url);
         exit;
     } else {
         $expires = LONG_EXPIRES;
         // for 15 days
         $user = new User();
         $user->login_name = $this->reg_user->newuser->login_name;
         $user->password = $this->reg_user->newuser->password;
         $token = $user->get_auth_token($expires);
         if (!empty($invitation_id)) {
             $invitation = '&InvID=' . $invitation_id;
         } else {
             if (!empty($group_invitation_id)) {
                 $invitation = '&GInvID=' . $group_invitation_id;
             } else {
                 $invitation = NULL;
             }
         }
         $user_type = NETWORK_WAITING_MEMBER;
         Network::join(PA::$network_info->network_id, $this->reg_user->newuser->user_id, $user_type);
         if (!$this->silent) {
             $activation_url = PA::$url . '/mail_action.php?action=activate&token=' . $token . $invitation;
             PAMail::send("activate_account", $this->reg_user->newuser, PA::$network_info, array('account.activation_url' => $activation_url));
         }
         global $app;
         $er_msg = urlencode("Check your email for activation code.");
         $app->redirect(PA::$url . PA_ROUTE_SYSTEM_MESSAGE . "?show_msg=7013&msg_type=info&redirect_url=" . urlencode(PA::$url . '/' . FILE_LOGIN));
     }
     //end if email validation is set
 }
Exemple #11
0
 function handle_join()
 {
     global $network_info;
     $invitation_id = isset($_REQUEST['InvID']) ? $_REQUEST['InvID'] : null;
     $group_invitation_id = isset($_REQUEST['GInvID']) ? $_REQUEST['GInvID'] : null;
     $mother_network_info = Network::get_mothership_info();
     $extra = unserialize($mother_network_info->extra);
     if (!$this->reg_user->register($_POST, $network_info)) {
         // registration failed
         return;
     }
     if ($extra['email_validation'] == NET_NO) {
         // Success!
         register_session($this->reg_user->newuser->login_name, $this->reg_user->newuser->user_id, $this->reg_user->newuser->role, $this->reg_user->newuser->first_name, $this->reg_user->newuser->last_name, $this->reg_user->newuser->email, $this->reg_user->newuser->picture);
         if ($invitation_id) {
             // if an invitation to join a network
             $this->inv_error = "";
             $is_valid = Invitation::validate_invitation_id($invitation_id);
             if (!$is_valid) {
                 $msg = 7017;
                 // invalid network invitation
             }
             if (empty($msg)) {
                 try {
                     // try to except invitation
                     $new_invite = new Invitation();
                     $new_invite->inv_id = $invitation_id;
                     $new_invite->inv_user_id = $this->reg_user->newuser->user_id;
                     $new_invite->accept();
                     $inv_obj = Invitation::load($invitation_id);
                     $user_obj = new User();
                     $user_obj->load((int) $inv_obj->user_id);
                     //if invitation is for private network
                     if ($network_info->type == PRIVATE_NETWORK_TYPE) {
                         $user_type = NULL;
                         if ($network_info->owner_id == $inv_obj->user_id) {
                             $user_type = NETWORK_MEMBER;
                         }
                         Network::join($network_info->network_id, $this->reg_user->newuser->user_id, $user_type);
                     }
                     $msg = 7016;
                     $relation_type_id = Relation::get_relation((int) $inv_obj->user_id, (int) $this->reg_user->newuser->user_id);
                     $relation_type = Relation::lookup_relation_type($relation_type_id);
                     $invited_user_url = url_for('user_blog', array('login' => $this->reg_user->newuser->login_name));
                     // data for passing in common mail method
                     $array_of_data = array('first_name' => $this->reg_user->newuser->first_name, 'last_name' => $this->reg_user->newuser->last_name, 'user_name' => $this->reg_user->newuser->login_name, 'user_id' => $this->reg_user->newuser->user_id, 'invited_user_id' => $inv_obj->user_id, 'invited_user_name' => $user_obj->login_name, 'mail_type' => 'invite_accept_pa', 'to' => $user_obj->email, 'network_name' => $network_info->name, 'relation_type' => $relation_type, 'config_site_name' => PA::$site_name, 'invited_user_url' => $invited_user_url);
                     auto_email_notification_members('invitation_accept', $array_of_data);
                 } catch (PAException $e) {
                     $this->inv_error = $e->message;
                     $this->reg_user->msg = "{$e->message}";
                     $error_inv = TRUE;
                 }
                 if ($error_inv == TRUE) {
                     // if invitation fails, then do login again
                     header("Location: " . PA::$url . "/login.php?msg=" . $this->reg_user->msg . "&return={$return_url}");
                     exit;
                 }
             }
             $redirect_url = 'homepage.php?msg=' . $msg;
         } else {
             if ($group_invitation_id) {
                 // if an invitation to join a group
                 // User registration is in response to a group invitation, so
                 // now that the user is registered, handle the group invitation.
                 try {
                     $is_valid_ginv = Invitation::validate_group_invitation_id($group_invitation_id);
                     if (!$is_valid_ginv) {
                         $msg = 3001;
                     }
                 } catch (PAException $e) {
                     $this->inv_error = "{$e->message}";
                 }
                 if (empty($msg)) {
                     //if group invitation is valid, and no error yet
                     try {
                         $new_invite = new Invitation();
                         $new_invite->inv_id = $group_invitation_id;
                         $new_invite->inv_user_id = $this->reg_user->newuser->user_id;
                         $new_invite->accept();
                         //get collection_id
                         $Ginv = Invitation::load($group_invitation_id);
                         $gid = $Ginv->inv_collection_id;
                     } catch (PAException $e) {
                         $this->reg_user->msg = "{$e->message}";
                         $this->reg_user->error = TRUE;
                         print $this->reg_user->msg;
                     }
                     $redirect_url = "group.php?gid={$gid}&action=join&GInvID={$group_invitation_id}";
                 } else {
                     //else redirect registered user to its page.
                     $redirect_url = "user.php?msg_id={$msg}";
                 }
                 // end of if group invitation is valid
             }
         }
         if (empty($redirect_url)) {
             // if no url is set yet
             // not a group invitation, so redirect to private user page when done
             $redirect_url = "user.php";
         }
         header("Location: " . PA::$url . "/{$redirect_url}");
         exit;
     } else {
         $expires = LONG_EXPIRES;
         // for 15 days
         $user = new User();
         $user->login_name = $this->reg_user->newuser->login_name;
         $user->password = $this->reg_user->newuser->password;
         $token = $user->get_auth_token($expires);
         if (!empty($invitation_id)) {
             $invitation = '&InvID=' . $invitation_id;
         } else {
             if (!empty($group_invitation_id)) {
                 $invitation = '&GInvID=' . $group_invitation_id;
             } else {
                 $invitation = NULL;
             }
         }
         $name = $user->login_name;
         $activation_url = PA::$url . '/mail_action.php?action=activate&token=' . $token . $invitation;
         $subject = 'Hi ' . $this->reg_user->newuser->login_name . '!  Please activate your ' . PA::$site_name . ' account.';
         $message = "Hi {$name} , \n Activate your people aggregator account by clicking the following link: \n {$activation_url}";
         $to = $this->reg_user->newuser->email;
         $mail_type = 'activate_account';
         $array_of_data = array('subject' => $subject, 'message' => $message);
         // send mail
         $check = pa_mail($to, $mail_type, $array_of_data);
         // redirect to home page.
         header("Location: " . PA::$url . "/homepage.php?msg=7013");
         exit;
     }
     //end if email validation is set
 }
 private function handlePOST_addChild($request_data)
 {
     global $error_msg;
     $error = FALSE;
     $login_name = trim($_POST['login_name']);
     $first_name = stripslashes(trim($_POST['first_name']));
     $last_name = stripslashes(trim($_POST['last_name']));
     $email = trim($_POST['email']);
     $password = trim($_POST['password']);
     $use_parent_email = $_POST['use_parent_email'];
     //echo "<pre>".print_r($_POST, 1)."</pre>"; die();
     if (!isset($_POST['state'])) {
         if (isset($_POST['stateOther'])) {
             $_POST['state'] = $_POST['stateOther'];
         }
     }
     if (isset($_POST['stateOther'])) {
         unset($_POST['stateOther']);
     }
     $msg = NULL;
     if (!Validation::validate_email($email) && !empty($_POST['email'])) {
         $email_invalid = TRUE;
         $error = TRUE;
         $msg .= '<br> Email address is not valid';
     }
     if (User::user_exist($login_name)) {
         $msg = "Username {$login_name} is already taken";
         $error = TRUE;
     }
     if ($error == FALSE) {
         $newuser = new User();
         $newuser->login_name = $login_name;
         $newuser->password = $password;
         $newuser->first_name = $first_name;
         $newuser->last_name = $last_name;
         $newuser->email = $email;
         $newuser->is_active = ACTIVE;
         if (!empty($_FILES['userfile']['name'])) {
             $myUploadobj = new FileUploader();
             //creating instance of file.
             $image_type = 'image';
             $file = $myUploadobj->upload_file(PA::$upload_path, 'userfile', true, true, $image_type);
             if ($file == false) {
                 $msg = $myUploadobj->error;
                 $error = TRUE;
             } else {
                 $newuser->picture = $file;
             }
         }
         if ($error == FALSE) {
             try {
                 if ($use_parent_email) {
                     $newuser->save($check_unique_email = false);
                 } else {
                     $newuser->save($check_unique_email = true);
                 }
                 if (!empty($file)) {
                     Storage::link($file, array("role" => "avatar", "user" => $newuser->user_id));
                 }
                 // creating message basic folders
                 Message::create_basic_folders($newuser->user_id);
                 // adding default relation
                 if ($newuser->user_id != SUPER_USER_ID) {
                     User_Registration::add_default_relation($newuser->user_id, PA::$network_info);
                 }
                 // adding default media as well as album
                 User_Registration::add_default_media($newuser->user_id, '', PA::$network_info);
                 User_Registration::add_default_media($newuser->user_id, '_audio', PA::$network_info);
                 User_Registration::add_default_media($newuser->user_id, '_video', PA::$network_info);
                 User_Registration::add_default_blog($newuser->user_id);
                 //adding default link categories & links
                 User_Registration::add_default_links($newuser->user_id);
                 // code for adding default desktop image for user
                 $desk_img = uihelper_add_default_desktopimage($newuser->user_id);
                 if (empty($desk_img)) {
                     $desktop_images = array('bay.jpg', 'everglade.jpg', 'bay_boat.jpg', 'delhi.jpg');
                     $rand_key = array_rand($desktop_images);
                     $desk_img = $desktop_images[$rand_key];
                 }
                 $states = array_values(PA::getStatesList());
                 $countries = array_values(PA::getCountryList());
                 $profile_keys = array('dob_day', 'dob_month', 'dob_year', 'homeAddress1', 'homeAddress2', 'city', 'state', 'country', 'postal_code', 'phone', 'use_parent_email');
                 $profile_data = array();
                 filter_all_post($_POST);
                 //filters all data of html
                 foreach ($profile_keys as $k => $pkey) {
                     if (!empty($_POST[$pkey])) {
                         if ($pkey == 'state' && $_POST[$pkey] >= 0) {
                             $prof_rec = array('uid' => $newuser->user_id, 'name' => $pkey, 'value' => $states[$_POST[$pkey]], 'type' => GENERAL, 'perm' => 1);
                         } else {
                             if ($pkey == 'country' && $_POST[$pkey] >= 0) {
                                 $prof_rec = array('uid' => $newuser->user_id, 'name' => $pkey, 'value' => $countries[$_POST[$pkey]], 'type' => GENERAL, 'perm' => 1);
                             } else {
                                 $prof_rec = array('uid' => $newuser->user_id, 'name' => $pkey, 'value' => $_POST[$pkey], 'type' => GENERAL, 'perm' => 1);
                             }
                         }
                         $profile_data[] = $prof_rec;
                     }
                 }
                 $profile_data[] = array('uid' => $newuser->user_id, 'name' => 'user_caption_image', 'value' => $desk_img, 'type' => GENERAL, 'perm' => 1);
                 //     echo "<pre>".print_r($profile_data,1)."</pre>";
                 $newuser->save_user_profile($profile_data, GENERAL);
                 //if new user is created in a network then he must set as a joined user
                 if (!empty(PA::$network_info)) {
                     $by_admin = true;
                     Network::join(PA::$network_info->network_id, $newuser->user_id, NETWORK_MEMBER, $by_admin);
                     // $by_admin = true overrides the
                     // user_waiting status if it would get set
                     // this is an admin action, so we want it to happen in any case
                 }
                 $user_joined = $this->family->join((int) $newuser->user_id, $newuser->email, null);
                 if ($user_joined) {
                     // deal with TypedGroup Relations
                     require_once "api/Entity/TypedGroupEntityRelation.php";
                     $type = 'child';
                     TypedGroupEntityRelation::set_relation($newuser->user_id, $this->family->collection_id, $type);
                     if ($type == 'child') {
                         // if user type == child remove LoginUser and GroupMember roles
                         $newuser->delete_user_role();
                         // then assign 'Child' role only
                         $_extra = serialize(array('user' => false, 'network' => false, 'groups' => array($this->family->collection_id)));
                         $user_roles[] = array('role_id' => CHILD_MEMBER_ROLE, 'extra' => $_extra);
                         $newuser->set_user_role($user_roles);
                     }
                 }
                 $msg = __("Child's account was successfully created");
             } catch (PAException $e) {
                 $msg = $e->message;
             }
         }
         // end if
     }
     //end if
     $error_msg = $msg;
 }
Exemple #13
0
require_once "{$path_prefix}/api/Message/Message.php";
require_once "{$path_prefix}/web/includes/functions/auto_email_notify.php";
default_exception();
$parameter = js_includes("all");
$header = 'header.tpl';
//default network header while creating groups. While group editing header_group.tpl will be used.
$title = "Request to join";
html_header($title, $parameter);
$optional_parameters = "onload=\"{$onload}\"";
html_body($optional_parameters);
if (!empty($_POST['request'])) {
    //code for requesting
    $error = FALSE;
    $success = FALSE;
    try {
        $request_sent = Network::join($network_info->network_id, $_SESSION['user']['id']);
        if ($request_sent) {
            $success = TRUE;
        }
    } catch (PAException $e) {
        $join_error = $e->message;
        $error = TRUE;
    }
    if ($error) {
        $error_msg = "Your request to join this network could not be sent due to following reason: " . $join_error . ". You can go back to the home network by clicking 'Return to home network'";
    } else {
        $success_msg = "Your request to join this network has been successfully sent to the moderator of this network. The Moderator will check this request and approve or deny the request. You can go back to mother network by clicking the button 'Return to home network'";
    }
}
if (!empty($_POST['back'])) {
    //redirect to mother network
 function register($params, $network_info = NULL)
 {
     $this->newuser = new User();
     // filter input parameters (this is the same as filter_all_post())
     $params = Validation::get_input_filter(FALSE)->process($params);
     $login_name = trim($params['login_name']);
     $first_name = trim($params['first_name']);
     $last_name = trim(@$params['last_name']);
     // not mandatory
     $email = trim($params['email']);
     $password = trim($params['password']);
     $confirm_password = trim($params['confirm_password']);
     $validate_array = array('login_name' => 'Login name', 'first_name' => 'First name', 'password' => 'Password', 'confirm_password' => 'Confirm password', 'email' => 'Email');
     $this->msg = '';
     $this->error = FALSE;
     foreach ($validate_array as $key => $value) {
         if (empty($params[$key])) {
             $this->msg .= "\n" . $value . " is mandatory";
             $this->error = TRUE;
         }
     }
     if (strlen($this->msg) > 0) {
         $this->msg = "\n" . "Fields marked with * must not be left empty" . $this->msg;
     }
     $error_login = FALSE;
     if (empty($login_name)) {
         $error_login = TRUE;
         $this->error = TRUE;
     }
     if (is_numeric($login_name)) {
         // Here we check the login name  is numeric or not
         if (strlen($this->msg) > 0) {
             $this->msg .= "\n";
         }
         $this->msg .= "Login name must not be numeric";
         $error_login = TRUE;
         $this->error = TRUE;
     }
     if (is_numeric($first_name)) {
         // Here we check the first  name  is numeric or not
         if (strlen($this->msg) > 0) {
             $this->msg .= "\n";
         }
         $this->msg .= "First name must not be numeric";
         $error_login = TRUE;
         $this->error = TRUE;
     }
     if (is_numeric($last_name)) {
         // Here we check the last name  is numeric or not
         if (strlen($this->msg) > 0) {
             $this->msg .= "\n";
         }
         $this->msg .= "Last name must not be numeric";
         $error_login = TRUE;
         $this->error = TRUE;
     }
     // if error occur than no need to checks these errors
     if (!$this->error) {
         if (!Validation::validate_email($email)) {
             $email_invalid = TRUE;
             $this->array_of_errors['error_email'] = $email_invalid;
             $this->error = TRUE;
             $this->msg .= " E-mail address ({$email}) is not valid";
         }
         if ($password != $confirm_password) {
             $this->msg .= "\nPassword and Confirm Password do not match.";
             $error_password_conf = TRUE;
             $this->error = TRUE;
         }
         if (strlen($password) > 15) {
             $this->msg .= "\nThe password must be less than 15 characters.";
             $error_password_l = TRUE;
             $this->error = TRUE;
         }
         if (strlen($password) < 5) {
             $this->msg .= "\nThe password must be longer than 5 characters.";
             $error_password_g = TRUE;
             $this->error = TRUE;
         }
     }
     if (User::user_exist($login_name)) {
         $this->msg = "Login name {$login_name} is already taken";
         $error_login = TRUE;
         $this->error = TRUE;
     } elseif (User::user_existed($login_name)) {
         $this->msg = "Login name {$login_name} has been used in the past; it belongs to a deleted user.";
         $error_login = $this->error = TRUE;
     }
     $this->array_of_errors = array("error_login" => $error_login, "error_first_name" => @$error_first_name, "error_email" => @$error_email, "error_password_conf" => @$error_password_conf, "error_password_l" => @$error_password_l, "error_password_g" => @$error_password_g);
     if ($this->error != TRUE) {
         $this->newuser->login_name = $login_name;
         //TODO: change to md5
         $this->newuser->password = $password;
         $this->newuser->first_name = $first_name;
         $this->newuser->last_name = $last_name;
         $this->newuser->email = $email;
         if (!empty($params['user_filename'])) {
             $user_fn_base = basename($params['user_filename']);
             if (file_exists(PA::$upload_path . $user_fn_base)) {
                 $this->newuser->picture = $user_fn_base;
             }
         }
         if ($this->error != TRUE) {
             try {
                 $save_error = FALSE;
                 $extra = unserialize($network_info->extra);
                 if ($extra['email_validation'] == NET_NO) {
                     // if email validation not required
                     $this->newuser->is_active = ACTIVE;
                 } else {
                     $this->newuser->is_active = UNVERIFIED;
                 }
                 $this->newuser->save();
                 // saving data in user profile data also -- for searching making more easier
                 $data_array = array(0 => array('uid' => $this->newuser->user_id, 'name' => 'first_name', 'value' => $this->newuser->first_name, 'type' => BASIC, 'perm' => 1), 1 => array('uid' => $this->newuser->user_id, 'name' => 'last_name', 'value' => $this->newuser->last_name, 'type' => BASIC, 'perm' => 1));
                 $this->newuser->save_user_profile($data_array, BASIC);
                 // saving default notification for user from network notification setting
                 $user_notification = array();
                 $profile = array();
                 $user_notification = $extra['notify_members'];
                 $user_notification['msg_waiting_blink'] = $extra['msg_waiting_blink'];
                 $profile['settings']['name'] = 'settings';
                 $profile['settings']['value'] = serialize($user_notification);
                 $this->newuser->save_profile_section($profile, 'notifications');
                 // default notification for user ends
                 $desktop_images = User_Registration::get_default_desktopimage($this->newuser->user_id, $network_info);
                 // code for adding default desktop image for user
                 if ($desktop_images == "") {
                     $desktop_images = array('bay.jpg', 'everglade.jpg', 'bay_boat.jpg', 'delhi.jpg');
                     $rand_key = array_rand($desktop_images);
                     $desk_img = $desktop_images[$rand_key];
                 } else {
                     $desk_img = $desktop_images;
                 }
                 $data_array = array(0 => array('uid' => $this->newuser->user_id, 'name' => 'user_caption_image', 'value' => $desk_img, 'type' => GENERAL, 'perm' => 1));
                 //}
                 $this->newuser->save_user_profile($data_array, GENERAL);
                 if ($extra['email_validation'] == NET_NO) {
                     //if email validation is not required
                     // creating message basic folders
                     Message::create_basic_folders($this->newuser->user_id);
                     // adding default relation
                     if ($this->newuser->user_id != SUPER_USER_ID) {
                         User_Registration::add_default_relation($this->newuser->user_id, $network_info);
                     }
                     // adding default media as well as album
                     User_Registration::add_default_media($this->newuser->user_id, '', $network_info);
                     User_Registration::add_default_media($this->newuser->user_id, '_audio', $network_info);
                     User_Registration::add_default_media($this->newuser->user_id, '_video', $network_info);
                     User_Registration::add_default_blog($this->newuser->user_id);
                     //adding default link categories & links
                     User_Registration::add_default_links($this->newuser->user_id);
                     // adding header image
                     User_Registration::add_default_header($this->newuser->user_id);
                     // Making user member of a network if he is registering to PA from a network
                     if (!empty($network_info) && $network_info->type != PRIVATE_NETWORK_TYPE) {
                         Network::join($network_info->network_id, $this->newuser->user_id);
                         $params['uid'] = $this->newuser->user_id;
                         auto_email_notification('some_joins_a_network', $params);
                     }
                 }
             } catch (PAException $e) {
                 $this->msg = $e->message;
                 if ($e->code == USER_EMAIL_NOT_UNIQUE) {
                     $this->msg = "Email Address has already been taken, please enter other email address.";
                 }
                 $save_error = TRUE;
                 if ($e->message == "The email address is invalid.") {
                     $email_invalid = TRUE;
                     $this->array_of_errors['error_email'] = $email_invalid;
                 }
             }
         }
     }
     if ($this->error == TRUE || $save_error == TRUE) {
         $this->msg = "Sorry! your registration failed. " . $this->msg;
         return FALSE;
     }
     // success!
     return TRUE;
 }