/**
	 * resend invite
	 *
	 * @param int       $id
	 * @param UserTable $user
	 */
	private function sendInvite( $id, $user )
	{
		global $_CB_framework;

		$row			=	new InviteTable();

		$row->load( (int) $id );

		$returnUrl		=	$_CB_framework->pluginClassUrl( $this->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $row->get( 'group' ) ) );

		if ( $row->get( 'id' ) ) {
			if ( ! CBGroupJive::canAccessGroup( $row->group(), $user ) ) {
				cbRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' );
			} elseif ( $user->get( 'id' ) != $row->get( 'user_id' ) ) {
				cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to send this invite.' ), 'error' );
			} elseif ( ! CBGroupJive::isModerator( $user->get( 'id' ) ) ) {
				if ( ( $row->group()->get( 'published' ) == -1 ) || ( ( ! $this->params->get( 'groups_invites_display', 1 ) ) && ( $row->group()->get( 'type' ) != 3 ) ) ) {
					cbRedirect( $returnUrl, CBTxt::T( 'You do not have access to invites in this group.' ), 'error' );
				}
			}
		} else {
			cbRedirect( $returnUrl, CBTxt::T( 'Invite does not exist.' ), 'error' );
		}

		if ( ! $row->send() ) {
			cbRedirect( $returnUrl, CBTxt::T( 'GROUP_INVITE_FAILED_TO_SEND', 'Invite failed to send. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' );
		}

		cbRedirect( $returnUrl, CBTxt::T( 'Invite sent successfully!' ) );
	}
Пример #2
0
	/**
	 * render frontend invite list
	 *
	 * @param string             $to
	 * @param UserTable[]        $users
	 * @param InviteTable        $invite
	 * @param GroupTable         $group
	 * @param UserTable          $user
	 * @param CBplug_cbgroupjive $plugin
	 * @return string
	 */
	static function showInviteList( $to, $users, $invite, $group, $user, $plugin )
	{
		global $_CB_framework;

		$js								=	"$( '.gjButtonInvite' ).on( 'click', function() {"
										.		"var from = $( this ).closest( 'form' );"
										.		"from.find( '#selected' ).val( $( this ).data( 'user-id' ) );"
										.		"from.find( '.gjButtonInvite' ).addClass( 'disabled' ).prop( 'disabled', true );"
										.		"from.submit();"
										.	"});";

		$_CB_framework->outputCbJQuery( $js );

		$_CB_framework->enqueueMessage( CBTxt::T( 'Multiple matching users found. Please select the user to invite. If you do not see the user you are looking for please be more specific.' ) );

		$pageTitle					=	CBTxt::T( 'INVITE_LIST_TO', 'Invite: [to]', array( '[to]' => $to ) );

		$_CB_framework->setPageTitle( $pageTitle );

		$return						=	'<div class="gjInviteList">'
									.		'<form action="' . $_CB_framework->pluginClassUrl( $plugin->element, true, array( 'action' => 'invites', 'func' => 'save', 'id' => (int) $invite->get( 'id' ) ) ) . '" method="post" enctype="multipart/form-data" name="gjInviteListForm" id="gjInviteListForm" class="cb_form gjInviteListForm form-auto">'
									.			( $pageTitle ? '<div class="gjInviteListTitle page-header"><h3>' . $pageTitle . '</h3></div>' : null )
									.			'<div class="gjInviteListRows">';

		foreach ( $users as $userId ) {
			$cbUser					=	CBuser::getInstance( (int) $userId, false );

			$return					.=				'<div class="gjInviteListUser gjContainerBox img-thumbnail">'
									.					'<div class="gjContainerBoxHeader">'
									.						'<div class="gjContainerBoxCanvas text-left">'
									.							$cbUser->getField( 'canvas', null, 'html', 'none', 'profile', 0, true )
									.						'</div>'
									.						'<div class="gjContainerBoxLogo text-left">'
									.							$cbUser->getField( 'avatar', null, 'html', 'none', 'list', 0, true )
									.						'</div>'
									.					'</div>'
									.					'<div class="gjContainerBoxBody text-left">'
									.						'<div class="gjContainerBoxTitle">'
									.							$cbUser->getField( 'onlinestatus', null, 'html', 'none', 'list', 0, true, array( '_imgMode' => 1 ) )
									.							' <strong>' . $cbUser->getField( 'formatname', null, 'html', 'none', 'list', 0, true ) . '</strong>'
									.						'</div>'
									.						'<div class="gjContainerBoxButton text-right">'
									.							'<button type="button" class="gjButton gjButtonInvite btn btn-xs btn-success" data-user-id="' . (int) $userId . '">' . CBTxt::T( 'Invite' ) . '</button>'
									.						'</div>'
									.					'</div>'
									.				'</div>';
		}

		$return						.=			'</div>'
									.			'<div class="form-group cb_form_line clearfix">'
									.				'<input type="button" value="' . htmlspecialchars( CBTxt::T( 'Cancel' ) ) . '" class="gjButton gjButtonCancel btn btn-default" onclick="window.location.href = \'' . $_CB_framework->pluginClassUrl( $plugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $group->get( 'id' ) ) ) . '\';" />'
									.			'</div>'
									.			'<input type="hidden" id="selected" name="selected" value="0" />';

		if ( ! $invite->get( 'id' ) ) {
			$return					.=			'<input type="hidden" id="to" name="to" value="' . htmlspecialchars( $to ) . '" />'
									.			'<input type="hidden" id="group" name="group" value="' . (int) $group->get( 'id' ) . '" />'
									.			'<input type="hidden" id="message" name="message" value="' . htmlspecialchars( $invite->get( 'message' ) ) . '" />';
		}

		$return						.=			'<input type="hidden" id="token" name="token" value="' . htmlspecialchars( md5( $invite->get( 'user_id' ) . $to . $invite->get( 'group' ) . $invite->get( 'message' ) . $_CB_framework->getCfg( 'secret' ) ) ) . '" />'
									.			cbGetSpoofInputTag( 'plugin' )
									.		'</form>'
									.	'</div>';

		$_CB_framework->setMenuMeta();

		echo $return;
	}
Пример #3
0
	/**
	 * @return bool
	 */
	public function check()
	{
		if ( $this->get( 'user_id' ) == '' ) {
			$this->setError( CBTxt::T( 'Owner not specified!' ) );

			return false;
		} elseif ( $this->get( 'group' ) == '' ) {
			$this->setError( CBTxt::T( 'Group not specified!' ) );

			return false;
		} elseif ( ( $this->get( 'email' ) == '' ) && ( $this->get( 'user' ) == '' ) ) {
			$this->setError( CBTxt::T( 'Recipient not specified or invalid!' ) );

			return false;
		} else {
			$group					=	$this->group();

			if ( ! $group->get( 'id' ) ) {
				$this->setError( CBTxt::T( 'Group does not exist!' ) );

				return false;
			} elseif ( ! $this->get( 'id' ) ) {
				$user				=	new \CB\Database\Table\UserTable();

				if ( $this->get( 'email' ) ) {
					$user->load( array( 'email' => $this->get( 'email' ) ) );
				} elseif ( $this->get( 'user' ) ) {
					$user->load( (int) $this->get( 'user' ) );

					if ( ! $user->get( 'id' ) ) {
						$this->setError( CBTxt::T( 'The user you are inviting does not exist!' ) );

						return false;
					}
				}

				if ( $user->get( 'id' ) ) {
					if ( $this->get( 'user_id' ) == $user->get( 'id' ) ) {
						$this->setError( CBTxt::T( 'You can not invite your self!' ) );

						return false;
					} elseif ( $group->get( 'user_id' ) == $user->get( 'id' ) ) {
						$this->setError( CBTxt::T( 'You can not invite the group owner!' ) );

						return false;
					} elseif ( $user->get( 'block' ) || ( ! $user->get( 'approved' ) ) || ( ! $user->get( 'confirmed' ) ) ) {
						$this->setError( CBTxt::T( 'The user you are inviting does not exist!' ) );

						return false;
					} else {
						$groupUser	=	new UserTable();

						$groupUser->load( array( 'group' => (int) $this->get( 'group' ), 'user_id' => (int) $user->get( 'id' ) ) );

						if ( $groupUser->get( 'id' ) ) {
							$this->setError( CBTxt::T( 'The user you are inviting already belongs to this group!' ) );

							return false;
						}
					}
				}

				$invite				=	new InviteTable();

				if ( $this->get( 'email' ) ) {
					$invite->load( array( 'group' => (int) $this->get( 'group' ), 'email' => $this->get( 'email' ) ) );

					if ( $invite->get( 'id' ) ) {
						$this->setError( CBTxt::T( 'The email address you are inviting has already been invited to this group!' ) );

						return false;
					}
				} elseif ( $this->get( 'user' ) ) {
					$invite->load( array( 'group' => (int) $this->get( 'group' ), 'user' => (int) $this->get( 'user' ) ) );

					if ( $invite->get( 'id' ) ) {
						$this->setError( CBTxt::T( 'The user you are inviting has already been invited to this group!' ) );

						return false;
					}
				}
			}
		}

		return true;
	}
Пример #4
0
	/**
	 * render frontend invite edit
	 *
	 * @param InviteTable        $row
	 * @param array              $input
	 * @param GroupTable         $group
	 * @param UserTable          $user
	 * @param CBplug_cbgroupjive $plugin
	 * @return string
	 */
	static function showInviteEdit( $row, $input, $group, $user, $plugin )
	{
		global $_CB_framework, $_PLUGINS;

		$js							=	"$( '.gjInviteConnection' ).on( 'change', function() {"
									.		"if ( $( this ).val() != 0 ) {"
									.			"$( '.gjInviteOther' ).addClass( 'hidden' );"
									.			"$( this ).parent().css({ display: 'inline' });"
									.		"} else {"
									.			"$( '.gjInviteOther' ).removeClass( 'hidden' );"
									.			"$( this ).parent().css({ display: 'block' });"
									.		"}"
									.	"});";

		$_CB_framework->outputCbJQuery( $js );

		$pageTitle					=	( $row->get( 'id' ) ? CBTxt::T( 'Edit Invite' ) : CBTxt::T( 'New Invite' ) );

		$_CB_framework->setPageTitle( $pageTitle );

		cbValidator::loadValidation();
		initToolTip();

		$isModerator				=	CBGroupJive::isModerator( $user->get( 'id' ) );
		$return						=	null;

		$_PLUGINS->trigger( 'gj_onBeforeDisplayInviteEdit', array( &$return, &$row, &$input, $group, $user ) );

		$return						.=	'<div class="gjInviteEdit">'
									.		'<form action="' . $_CB_framework->pluginClassUrl( $plugin->element, true, array( 'action' => 'invites', 'func' => 'save', 'id' => (int) $row->get( 'id' ) ) ) . '" method="post" enctype="multipart/form-data" name="gjInviteEditForm" id="gjInviteEditForm" class="cb_form gjInviteEditForm form-auto cbValidation">'
									.			( $pageTitle ? '<div class="gjInviteEditTitle page-header"><h3>' . $pageTitle . '</h3></div>' : null );

		if ( ! $row->get( 'id' ) ) {
			$return					.=			'<div class="cbft_text cbtt_input form-group cb_form_line clearfix">'
									.				'<label for="to" class="col-sm-3 control-label">' . CBTxt::T( 'To' ) . '</label>'
									.				'<div class="cb_field col-sm-9">';

			if ( $plugin->params->get( 'groups_invites_list', 0 ) && $input['list'] ) {
				$return				.=					'<div style="margin-bottom: 10px;">' . $input['list'] . '</div>';
			}

			$return					.=					$input['to'];

			if ( $plugin->params->get( 'groups_invites_list', 0 ) && $input['list'] ) {
				$return				.=					getFieldIcons( null, 1, null, CBTxt::T( 'GROUP_INVITE_BY_LIST', 'Input the recipient as [invite_by] or select one of your connections.', array( '[invite_by]' => implode( ', ', $input['invite_by'] ) ) ) );
			} else {
				$return				.=					getFieldIcons( null, 1, null, CBTxt::T( 'GROUP_INVITE_BY', 'Input the recipient as [invite_by].', array( '[invite_by]' => implode( ', ', $input['invite_by'] ) ) ) );
			}

			$return					.=				'</div>'
									.			'</div>';
		}

		$return						.=			'<div class="cbft_textarea cbtt_textarea form-group cb_form_line clearfix">'
									.				'<label for="message" class="col-sm-3 control-label">' . CBTxt::T( 'Message' ) . '</label>'
									.				'<div class="cb_field col-sm-9">'
									.					$input['message']
									.					getFieldIcons( null, 0, null, CBTxt::T( 'Optionally input private message to include with the invite.' ) )
									.				'</div>'
									.			'</div>';

		if ( ( ! $isModerator ) && $plugin->params->get( 'groups_invites_captcha', 0 ) ) {
			$_PLUGINS->loadPluginGroup( 'user' );

			$captcha				=	$_PLUGINS->trigger( 'onGetCaptchaHtmlElements', array( false ) );

			if ( ! empty( $captcha ) ) {
				$captcha			=	$captcha[0];

				$return				.=			'<div class="form-group cb_form_line clearfix">'
									.				'<label class="col-sm-3 control-label">' . CBTxt::T( 'Captcha' ) . '</label>'
									.				'<div class="cb_field col-sm-9">'
									.					( isset( $captcha[0] ) ? $captcha[0] : null )
									.				'</div>'
									.			'</div>'
									.			'<div class="form-group cb_form_line clearfix">'
									.				'<div class="cb_field col-sm-offset-3 col-sm-9">'
									.					str_replace( 'inputbox', 'form-control', ( isset( $captcha[1] ) ? $captcha[1] : null ) )
									.					getFieldIcons( null, 1, null )
									.				'</div>'
									.			'</div>';
			}
		}

		$return						.=			'<div class="form-group cb_form_line clearfix">'
									.				'<div class="col-sm-offset-3 col-sm-9">'
									.					'<input type="submit" value="' . htmlspecialchars( ( $row->get( 'id' ) ? CBTxt::T( 'Update Invite' ) : CBTxt::T( 'Create Invite' ) ) ) . '" class="gjButton gjButtonSubmit btn btn-primary" ' . cbValidator::getSubmitBtnHtmlAttributes() . ' />'
									.					' <input type="button" value="' . htmlspecialchars( CBTxt::T( 'Cancel' ) ) . '" class="gjButton gjButtonCancel btn btn-default" onclick="cbjQuery.cbconfirm( \'' . addslashes( CBTxt::T( 'Are you sure you want to cancel? All unsaved data will be lost!' ) ) . '\' ).done( function() { window.location.href = \'' . $_CB_framework->pluginClassUrl( $plugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $group->get( 'id' ) ) ) . '\'; })" />'
									.				'</div>'
									.			'</div>'
									.			( ! $row->get( 'id' ) ? '<input type="hidden" id="group" name="group" value="' . (int) $group->get( 'id' ) . '" />' : null )
									.			cbGetSpoofInputTag( 'plugin' )
									.		'</form>'
									.	'</div>';

		$_PLUGINS->trigger( 'gj_onAfterDisplayInviteEdit', array( &$return, $row, $input, $group, $user ) );

		$_CB_framework->setMenuMeta();

		echo $return;
	}