Ejemplo n.º 1
0
function get_network_info()
{
    if (CURRENT_NETWORK_URL_PREFIX != 'www' && CURRENT_NETWORK_URL_PREFIX != '') {
        // not mother (home) network
        $network_info = Network::get_network_by_address(CURRENT_NETWORK_URL_PREFIX);
    } else {
        // home network
        $network_info = Network::get_mothership_info();
    }
    return $network_info;
}
 function safe_updates()
 {
     global $network_info;
     PA::$network_info = $network_info = Network::get_mothership_info();
     PA::$extra = unserialize(PA::$network_info->extra);
     $this->create_announce_tables();
     $this->add_all_users_to_mother_network();
     // run project specific updates and init settings
     if (!empty(PA::$config->project_safe_updates)) {
         // see if the settings file exists
         $file_path = PA::$core_dir . "/web/extra/" . PA::$config->project_safe_updates . "_safe_updates.php";
         if (file_exists($file_path)) {
             include $file_path;
         }
     }
 }
 function testUserRegistration()
 {
     $login = "******" . rand(10000, 99999);
     $firstName = 'Test';
     $lastName = 'User';
     $email = "{$login}@myelin.co.nz";
     $password = '******';
     $home_network = Network::get_mothership_info();
     $orig_member_count = $home_network->member_count;
     // register a new user
     $reg = new User_Registration();
     $this->assertTrue($reg->register(array('login_name' => $login, 'first_name' => $firstName, 'last_name' => $lastName, 'email' => $email, 'password' => $password, 'confirm_password' => $password), $home_network));
     $this->assertEquals(Network::get_member_count($home_network->network_id), $orig_member_count + 1);
     // test the user
     $new_user = $reg->newuser;
     $new_uid = (int) $new_user->user_id;
     $this->assertEquals($new_user->first_name, $firstName);
     $this->assertEquals($new_user->last_name, $lastName);
     $this->assertEquals($new_user->email, $email);
     // reload user and make sure it works
     $user = new User();
     $user->load($new_uid);
     $this->assertEquals($user->first_name, $firstName);
     $this->assertEquals($user->last_name, $lastName);
     $this->assertEquals($user->email, $email);
     // now delete the user
     User::delete($new_uid);
     // and try to load again
     $user_fail = new User();
     try {
         $user_fail->load($new_uid);
     } catch (PAException $e) {
         $this->assertEquals($e->getCode(), USER_NOT_FOUND);
     }
     // make sure member_count is correct
     $this->assertEquals(Network::get_member_count($home_network->network_id), $orig_member_count);
 }
 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;
 }
Ejemplo n.º 5
0
 /**
  * let the user join network
  * @access public
  * @param id of the network,uid of user
  * @return flag for joining request moderated or success message
  */
 static function join($network_id, $uid, $user_type = null)
 {
     // function modified just to have crude functionality for time being
     //TODO : when some one joins network do something
     global $default_sender;
     Logger::log("Enter: static function Network::join");
     if (Network::member_exists($network_id, $uid)) {
         //then make an entry for the network to be joined and user_id
         throw new PAException(OPERATION_NOT_PERMITTED, "Already a member of this network.");
     }
     $user_created = Dal::query_first("SELECT created FROM users WHERE user_id=?", array($uid));
     //find type of the network
     $type = Network::find_network_type($network_id);
     if ($type == PRIVATE_NETWORK_TYPE) {
         $user_type = empty($user_type) ? NETWORK_WAITING_MEMBER : $user_type;
         // see if user has already applied for the network
         $res = Dal::query("SELECT * FROM {networks_users} WHERE network_id = ? AND user_id = ? AND user_type = ? ", array($network_id, $uid, $user_type));
         if ($res->numRows() > 0) {
             throw new PAException(OPERATION_NOT_PERMITTED, "You have already requested to join this network.");
         }
     } else {
         $user_type = NETWORK_MEMBER;
     }
     $res = Dal::query("INSERT INTO {networks_users} (network_id, user_id, user_type, created) VALUES (?, ?, ?, ?)", array($network_id, $uid, $user_type, $user_created));
     //getting Mother network informaton
     $network_data = Network::get_mothership_info();
     //get the network_info of mother network such as network_id
     if (!Network::member_exists($network_data->network_id, $uid)) {
         //if not a member of mother network ie directly joining a network then make an entry for mother network_id and user_id
         $res = Dal::query("INSERT INTO {networks_users} (network_id, user_id, user_type, created) VALUES (?, ?, ?, ?)", array($network_data->network_id, $uid, NETWORK_MEMBER, $user_created));
     }
     // Update cached member count
     Network::update_network_member_count($network_id);
     return TRUE;
 }
 function testEmailNotification()
 {
     // test requires xdebug and xdebug_get_declared_vars().
     if (!extension_loaded('xdebug')) {
         echo ($msg = "Need xdebug extension for email notification test") . "\n";
         $this->markTestIncomplete($msg);
     }
     if (ini_get('xdebug.collect_vars') != 1) {
         echo ($msg = "need to set xdebug.collect_vars = 1") . "\n";
         $this->markTestIncomplete($msg);
     }
     $this->assertEquals($GLOBALS['this_test_requires_globals'], "test", "xdebug not working - or need to update phpunit?  see http://pear.php.net/bugs/bug.php?id=5053 for more info.");
     // hook mail()
     global $mail_testing_callback;
     $mail_testing_callback = array("EmailNotificationTest", "mail_hook");
     // load main network and get a fake owner user
     global $network_info, $owner;
     $network_info = Network::get_mothership_info();
     $owner = Test::get_test_user();
     // override destination so we get an e-mail
     $extra = unserialize($network_info->extra);
     $extra['notify_owner']['announcement']['value'] = NET_EMAIL;
     $extra['notify_owner']['content_to_homepage']['value'] = NET_EMAIL;
     $network_info->extra = serialize($extra);
     $this->assertEquals(count(EmailNotificationTest::$messages), 0);
     // now trigger a fake network announcement
     $owner_name = 'John Q. NetworkOwner';
     announcement(array('params' => array('aid' => "whatever"), 'owner_name' => $owner_name));
     $this->assertEquals(count(EmailNotificationTest::$messages), 1);
     $msg = EmailNotificationTest::$messages[0];
     $this->assertContains("nnouncement", $msg[1]);
     $this->assertContains("network", $msg[1]);
     $this->assertContains($owner_name, $msg[2]);
     $this->assertContains("nnouncement", $msg[2]);
     // now trigger a fake content posting to community blog
     $comm_blog_post = array('owner_name' => $owner_name, 'params' => array('first_name' => "Firstname", 'network_name' => "Network Name", 'user_id' => $owner->user_id, 'user_image' => $owner->picture, 'cid' => '1234', 'content_title' => 'Fake content title'));
     content_posted_to_comm_blog($comm_blog_post);
     $this->assertEquals(count(EmailNotificationTest::$messages), 2);
     $msg = EmailNotificationTest::$messages[1];
     $this->assertContains("Community Blog", $msg[1]);
     $this->assertContains("posted", $msg[1]);
     $this->assertContains($owner_name, $msg[2]);
     $this->assertContains("Firstname has posted", $msg[2]);
     echo "The site name is " . PA::$site_name . "\n";
     $this->assertContains(PA::$site_name, $msg[2]);
     /* The following test won't work yet -- as the site name is
                inserted in the messages early, so changing it now won't
                have any effect.
     
     	// now change the site name and make sure it shows up properly
     	$old_config_site_name = PA::$site_name;
     	$new_config_site_name = PA::$site_name = "Test site name - for EmailNotificationTest";
     	content_posted_to_comm_blog($comm_blog_post);
     	$this->assertEquals(count(EmailNotificationTest::$messages), 3);
     	$msg = EmailNotificationTest::$messages[2];
     	$this->assertContains("Community Blog", $msg[1]);
     	$this->assertContains("posted", $msg[1]);
     	$this->assertContains($owner_name, $msg[2]);
     	$this->assertContains("Firstname has posted", $msg[2]);
     	echo "The site name is ". PA::$site_name ."\n";
     	$this->assertContains(PA::$site_name, $msg[2]);
     	$this->assertNotContains($old_config_site_name, $msg[2]);
     	$this->assertNotContains("PeopleAggregator", $msg[2]);
     	*/
 }
$level_1 = $navigation_links['level_1'];
unset($level_1['highlight']);
if (PA::$network_info->type == MOTHER_NETWORK_TYPE) {
    $network_name = sprintf(__("%s Platform"), PA::$site_name);
} else {
    $network_name = ucfirst(PA::$network_info->name) . ' Network';
}
$level_2 = $navigation_links['level_2'];
if (!empty(PA::$config->simple['use_simplenav'])) {
    $level_3 = array();
    $left_user_public_links = array();
} else {
    $level_3 = $navigation_links['level_3'];
    $left_user_public_links = $navigation_links['left_user_public_links'];
}
$mother_network = Network::get_mothership_info();
$extra = unserialize($mother_network->extra);
$mothership_info = mothership_info();
?>
<!-- sidebar menu: : style can be found in sidebar.less -->
<ul class="sidebar-menu">
    <li class="header">MAIN NAVIGATION</li>
    <li class="treeview">
        <a href="<?php 
echo PA::$url . PA_ROUTE_HOME_PAGE;
?>
">
            <i class="fa fa-dashboard"></i> <span>Dashboard</span>
        </a>
    </li>
    <?php 
 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
 }
Ejemplo n.º 9
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
 }
 public function testAddUpdateDeleteEvent()
 {
     //    Dal::register_query_callback("explain_query");
     echo "getting a user\n";
     $user = Test::get_test_user();
     $testusername = $user->first_name . " " . $user->last_name;
     echo "test user = {$testusername}\n";
     /* setup some times and time strings */
     $today = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
     $tomorrow = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"));
     $yesterday = mktime(0, 0, 0, date("m"), date("d") - 1, date("Y"));
     $lastmonth = mktime(0, 0, 0, date("m") - 1, date("d"), date("Y"));
     $nextmonth = mktime(0, 0, 0, date("m") + 1, date("d"), date("Y"));
     $nextyear = mktime(0, 0, 0, date("m"), date("d"), date("Y") + 1);
     $oneday = 60 * 60 * 24;
     $simple_dateformat = "Y-m-d";
     /* use the constants in the format parameter */
     // something like: Mon, 15 Aug 2005 15:12:46 UTC
     $now_rfc822 = date(DATE_RFC822);
     // something like: 2000-07-01T00:00:00+00:00
     // $now_atom = date(DATE_ATOM);
     // create an Event
     echo "create and save Event\n";
     $e = new Event();
     $e->content_id = "http://myevent.info/1";
     // anything basically
     $e->user_id = $user->user_id;
     $e->event_title = "Test Event for {$testusername}";
     $now = time();
     $nowplusoneday = $now + $oneday;
     $e->start_time = date(DATE_ATOM, $now);
     $e->end_time = date(DATE_ATOM, $now + 60 * 60);
     // duration 1h
     $e->event_data = array('description' => "This Event takes place to test the class Event", 'start' => $now, 'end' => $now + 60 * 60);
     $e->save();
     // print_r($e);
     // see if we got it
     echo "Retrieving Event {$e->event_id}\n";
     $e2 = new Event();
     $e2->load($e->event_id);
     echo "Testing integrity of dates\n";
     // print_r($e2);
     // see if the stored timestamps match
     $this->assertEquals($now, $e2->event_data['start']);
     // see if our dates survived the DB conversion roundtrip
     $this->assertEquals($now, strtotime($e2->start_time));
     $this->assertEquals($now + 60 * 60, strtotime($e2->end_time));
     // create two EventAssociations
     $ea1 = new EventAssociation();
     $ea2 = new EventAssociation();
     $ea1->user_id = $user->user_id;
     $ea2->user_id = $user->user_id;
     // user EventAssocoiation
     $ea1->assoc_target_type = 'user';
     $ea1->assoc_target_id = $user->user_id;
     // could very well be other user
     $ea1->assoc_target_name = $testusername;
     $ea1->event_id = $e->event_id;
     $ea1->save();
     // network EventAssocoiation
     // find a network the user is member of
     // $networks = Network::get_user_networks($user->user_id);
     $network = Network::get_mothership_info();
     // use the mothership
     // print_r($network);
     $ea2->assoc_target_type = 'network';
     $ea2->assoc_target_id = $network->network_id;
     // could very well be other user
     $ea2->assoc_target_name = $network->name;
     $ea2->event_id = $e->event_id;
     $ea2->save();
     echo "Testing EventAssociations for Event {$e->event_id}\n";
     $assoc_ids = EventAssociation::find_for_event($e->event_id);
     // print_r($assoc_ids);
     $a_cnt = count($assoc_ids);
     $this->assertEquals($a_cnt, 2, "expected 2 assocs, got {$a_cnt}\n");
     echo "Testing EventAssociations::find_for_target_and_delta for Network\n";
     $assoc_ids = EventAssociation::find_for_target_and_delta('network', $network->network_id);
     // find_for_target_and_delta($target_type, $target_id, $range_start = NULL, $range_end = NULL)
     // print_r($assoc_ids);
     $a_cnt = count($assoc_ids);
     // we expect at least one (or more, the user might have others too)
     $this->assertTrue($a_cnt >= 1, "expected 1 or more assocs, got {$a_cnt}\n");
     echo "Testing EventAssociations::find_for_target_and_delta for Today\n";
     /*
     echo "yesterday = " . date(DATE_ATOM, $yesterday) . "\n";
     echo "today = " . date(DATE_ATOM, $today) . "\n";
     echo "event start_time = " . date(DATE_ATOM, strtotime($e2->start_time)) . "\n";
     echo "event end_time = " . date(DATE_ATOM, strtotime($e2->end_time)) . "\n";
     echo "tomorrow = " . date(DATE_ATOM, $tomorrow) . "\n";
     */
     $assoc_ids = EventAssociation::find_for_target_and_delta('network', $network->network_id, date(DATE_ATOM, $today), date(DATE_ATOM, $tomorrow));
     print_r($assoc_ids);
     /* 
     $assocs = EventAssociation::load_in_list($assoc_ids);
     print_r($assocs);
     */
     $a_cnt = count($assoc_ids);
     // we expect at least one (or more, the user might have others too)
     $this->assertTrue($a_cnt >= 1, "expected 1 or more assocs, got {$a_cnt}\n");
     echo "Testing if the EventAssociations now show up in Tomorrow's Calendar\n";
     $assoc_ids = EventAssociation::find_for_target_and_delta('network', $network->network_id, date(DATE_ATOM, $tomorrow), date(DATE_ATOM, $tomorrow + $oneday));
     print_r($assoc_ids);
     $a_cnt2 = count($assoc_ids);
     // we expect one less than before
     $this->assertTrue($a_cnt2 < $a_cnt, "expected " . $a_cnt - 1 . " assocs, got {$a_cnt2}\n");
     echo "Modifying original Event\n";
     $e2->title = "changed title";
     $e2->end_time = date(DATE_ATOM, $nextmonth);
     $e2->save();
     // see if we got it
     $e3 = new Event();
     $e3->load($e->event_id);
     echo "Testing integrity of dates again in the Event\n";
     // see if our dates survived the DB conversion roundtrip
     $this->assertEquals($now, strtotime($e3->start_time));
     $this->assertEquals(date(DATE_ATOM, strtotime($e3->end_time)), date(DATE_ATOM, $nextmonth));
     echo "Testing if modified dates made it to the EventAssociations\n";
     $assoc_ids = EventAssociation::find_for_event($e3->event_id);
     $assocs = EventAssociation::load_in_list($assoc_ids);
     echo "e3 end_time: " . date(DATE_ATOM, strtotime($assocs[0]->end_time)) . "\nnextmonth: " . date(DATE_ATOM, $nextmonth) . "\n";
     $this->assertEquals(date(DATE_ATOM, strtotime($assocs[0]->end_time)), date(DATE_ATOM, $nextmonth));
     echo "Testing if the EventAssociations now show up in Tomorrow's Calendar\n";
     echo "test range: " . date(DATE_ATOM, $tomorrow) . " - " . date(DATE_ATOM, $tomorrow + $oneday) . "\n";
     echo "event duration: " . date(DATE_ATOM, strtotime($e3->start_time)) . " - " . date(DATE_ATOM, strtotime($e3->end_time)) . "\n";
     // print_r($e3);
     $assoc_ids = EventAssociation::find_for_target_and_delta('network', $network->network_id, date(DATE_ATOM, $tomorrow), date(DATE_ATOM, $tomorrow + $oneday));
     print_r($assoc_ids);
     $a_cnt = count($assoc_ids);
     // we expect at least one (or more, the user might have others too)
     $this->assertTrue($a_cnt >= 1, "expected 1 or more assocs, got {$a_cnt}\n");
     echo "Deleting Event {$e->event_id}\n";
     Event::delete($e->event_id);
     // try loading
     $this->assertNull($e3->load($e->event_id));
     echo "Testing if all EventAssociations have been removed\n";
     $assoc_ids = EventAssociation::find_for_event($e->event_id);
     $a_cnt = count($assoc_ids);
     $this->assertEquals($a_cnt, 0, "expected 0 assocs, got {$a_cnt}\n");
 }