/** !! * This handles the data that is POSTed back to the page upon * submission of the form. There is a lot happening in here, * but it basically looks at the submitted data, figures out * what it is supposed to do with it (based on if the group is * being created or modified), then creates a new group or * updates the current data using the {@link handle_entity() } method. * * @param array $request_data All of the data POSTed back to the form. */ public function handlePOST($request_data) { require_once "web/includes/classes/CNFileUploader.php"; require_once "api/CNActivities/CNActivities.php"; require_once "api/cnapi_constants.php"; if ($request_data['addgroup']) { filter_all_post($request_data); $groupname = trim($request_data['groupname']); $body = trim($request_data['groupdesc']); $tag_entry = trim($request_data['group_tags']); $group_category = $request_data['group_category']; $header_image = NULL; $header_image_action = @$request_data['header_image_action']; $display_header_image = @$request_data['display_header_image']; $collection_id = NULL; $this->extra = NULL; if ($request_data['ccid']) { $collection_id = (int) $request_data['ccid']; $group = new Group(); $group->load($collection_id); // preserve group info we are not editing in this module // load group extra $extra = $group->extra; if (!empty($extra)) { $this->extra = unserialize($extra); } $header_image = $group->header_image; $header_image_action = $group->header_image_action; $display_header_image = $group->display_header_image; } $access = 0; // default access is 0 means public $reg_type = $request_data['reg_type']; if ($reg_type == REG_INVITE) { // if reg. type = "Invite" access is PRIVATE $access = ACCESS_PRIVATE; } $is_moderated = 0; // is moderated is 0 means contents appear immediately $group_tags = $request_data['group_tags']; if (empty($request_data['groupname'])) { $error_msg = 90222; } else { if (empty($group_category) && empty($error_msg)) { $error_msg = 90224; } else { if (empty($error_msg)) { try { if (empty($_FILES['groupphoto']['name'])) { $upfile = $request_data['file']; } else { $myUploadobj = new FileUploader(); //creating instance of file. $image_type = 'image'; $file = $myUploadobj->upload_file(PA::$upload_path, 'groupphoto', true, true, $image_type); if ($file == false) { throw new CNException(GROUP_PARAMETER_ERROR, __("File upload error: ") . $myUploadobj->error); } $upfile = $file; $avatar_uploaded = TRUE; } $exception_message = NULL; $result = Group::save_new_group($collection_id, $_SESSION['user']['id'], $groupname, $body, $upfile, $group_tags, $group_category, $access, $reg_type, $is_moderated, $header_image, $header_image_action, $display_header_image, $this->extra); $ccid = $result; $exception_message = 'Group creation failed: ' . $result; if (!is_numeric($result)) { throw new CNException(GROUP_CREATION_FAILED, $exception_message); } else { if (@$avatar_uploaded) { Storage::link($upfile, array("role" => "avatar", "group" => (int) $result)); } if (@$header_uploaded) { Storage::link($header_image, array("role" => "header", "group" => (int) $result)); } $this->gid = $this->id = $result; if (empty($request_data['gid'])) { $mail_type = $activity = 'group_created'; $act_text = ' created a new group'; } else { $mail_type = $activity = 'group_settings_updated'; $act_text = ' changed group settings '; } $group = new Group(); $group->load((int) $this->gid); PANotify::send($mail_type, PA::$network_info, PA::$login_user, $group); // notify network onwer $_group_url = PA::$url . PA_ROUTE_GROUP . '/gid=' . $result; $group_owner = new User(); $group_owner->load((int) $_SESSION['user']['id']); $activity_extra['info'] = $group_owner->first_name . $act_text; $activity_extra['group_name'] = $groupname; $activity_extra['group_id'] = $result; $activity_extra['group_url'] = $_group_url; $extra = serialize($activity_extra); $object = $result; if ($reg_type != REG_INVITE) { Activities::save($group_owner->user_id, $activity, $object, $extra); } // if we reached here than the group is created if (empty($request_data['gid'])) { // when a new group is created // so, we need to assign group admin role to group owner now: $role_extra = array('user' => false, 'network' => false, 'groups' => array($this->gid)); $user_roles[] = array('role_id' => GROUP_ADMIN_ROLE, 'extra' => serialize($role_extra)); $group_owner->set_user_role($user_roles); } if (!empty(PA::$config->useTypedGroups) && !empty($request_data['type'])) { $this->gid = $this->id; switch ($request_data['op']) { case 'create_entity': case 'edit_entity': $this->handleEntity($request_data); break; } } } } catch (CNException $e) { if ($e->code == GROUP_PARAMETER_ERROR) { $error_msg = $e->message; if (empty($groupname)) { $error_msg = 90222; } else { if (empty($group_category)) { $error_msg = 90224; } } } else { $error_msg = $e->message; } } } } } } //if form is posted $msg_array = array(); $msg_array['failure_msg'] = @$error_msg; $msg_array['success_msg'] = !empty($this->id) ? 90231 : 90221; $redirect_url = PA::$url . PA_ROUTE_GROUP; $query_str = "?gid=" . @$result; set_web_variables($msg_array, $redirect_url, $query_str); }
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; }
/** * Purpose: this function assign single or multiple roles to a user * @param $role * @return TRUE * */ public function assign_role_to_user($roles, $user_id) { Logger::log("Enter: function Roles::assign_role_to_user"); if (empty($roles) || empty($user_id)) { throw new CNException(REQUIRED_PARAMETERS_MISSING, "Some internal error occured while updating role."); } $user = new User(); $user->load($user_id); if (!is_array($roles)) { $roles = array($roles); } $user->set_user_role($roles); Logger::log("Exit: function Roles::assign_role_to_user"); }
/** * function used to delete a group or groups. * @param $user_id and $group_id */ public function delete_user_groups($user_id, $group_id = NULL) { $network_owner_id = (int) PA::$network_info->owner_id; //getting user groups $all_user_groups = Group::get_user_groups($user_id); if (count($all_user_groups) > 0) { foreach ($all_user_groups as $group) { $this->collection_id = $group['gid']; if ($group['access'] == OWNER) { // assign new Battalion/UGCGroup owner Group::set_user_type($user_id, (int) $group['gid'], MEMBER); // only MEMBER can leave a group! $this->leave($user_id); if (Group::member_exists((int) $group['gid'], $network_owner_id)) { // network owner is already member of group Group::set_user_type($network_owner_id, (int) $group['gid'], OWNER); // transfer ownership to network owner } else { Group::set_group_owner($network_owner_id, (int) $group['gid']); // insert new group owner } $role_id = GROUP_ADMIN_ROLE; $role_extra = array('user' => false, 'network' => false, 'groups' => array((int) $group['gid'])); $role = array('role_id' => $role_id, 'extra' => serialize($role_extra)); $net_owner = new User(); $net_owner->load($network_owner_id); $net_owner->set_user_role(array($role)); } else { if ($group['access'] == MEMBER || $group['access'] == MODERATOR) { if ($group['access'] == MODERATOR) { Group::set_user_type($user_id, (int) $group['gid'], MEMBER); // only MEMBER can leave a group! } //voiding user membership $this->leave($user_id); } } } } }