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

		$cbModerator			=	Application::User( (int) $user->get( 'id' ) )->isGlobalModerator();

		$row					=	new cbinvitesInviteTable();

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

		$canAccess				=	false;

		if ( $row->get( 'id' ) && ( $cbModerator || ( $row->get( 'user_id' ) == $user->get( 'id' ) ) ) ) {
			$canAccess			=	true;
		}

		$profileUrl				=	$_CB_framework->userProfileUrl( $row->get( 'user_id', $user->get( 'id' ) ), false, 'cbinvitesTab' );

		if ( $canAccess ) {
			if ( $row->isAccepted() ) {
				cbRedirect( $profileUrl, CBTxt::T( 'Invite already accepted and can not be deleted.' ), 'error' );
			}

			if ( ! $row->delete() ) {
				cbRedirect( $profileUrl, CBTxt::T( 'INVITE_FAILED_DELETE_ERROR', 'Invite failed to delete! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' );
			}

			cbRedirect( $profileUrl, CBTxt::T( 'Invite deleted successfully!' ) );
		} else {
			cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' );
		}
	}
예제 #2
0
	/**
	 * @param cbautoactionsActionTable $trigger
	 * @param UserTable $user
	 */
	public function execute( $trigger, $user )
	{
		global $_CB_database;

		if ( ! $this->installed() ) {
			if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
				var_dump( CBTxt::T( 'AUTO_ACTION_INVITE_NOT_INSTALLED', ':: Action [action] :: CB Invites is not installed', array( '[action]' => (int) $trigger->get( 'id' ) ) ) );
			}

			return;
		}

		foreach ( $trigger->getParams()->subTree( 'invite' ) as $row ) {
			/** @var ParamsInterface $row */
			$owner					=	$row->get( 'owner', null, GetterInterface::STRING );

			if ( ! $owner ) {
				$owner				=	(int) $user->get( 'id' );
			} else {
				$owner				=	(int) $trigger->getSubstituteString( $owner );
			}

			if ( ! $owner ) {
				if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
					var_dump( CBTxt::T( 'AUTO_ACTION_INVITE_NO_OWNER', ':: Action [action] :: CB Invites skipped due to missing owner', array( '[action]' => (int) $trigger->get( 'id' ) ) ) );
				}

				continue;
			}

			if ( $user->get( 'id' ) != $owner ) {
				$user				=	CBuser::getUserDataInstance( $owner );
			}

			switch ( (int) cbGetParam( $params, 'invite_mode', 1 ) ) {
				case 1:
					$invite			=	new cbinvitesInviteTable();

					$toArray		=	explode( ',', $trigger->getSubstituteString( $row->get( 'to', null, GetterInterface::STRING ) ) );

					foreach ( $toArray as $to ) {
						$invite->set( 'id', null );
						$invite->set( 'to', $to );
						$invite->set( 'subject', $trigger->getSubstituteString( $row->get( 'subject', null, GetterInterface::STRING ) ) );
						$invite->set( 'body', $trigger->getSubstituteString( $row->get( 'body', null, GetterInterface::RAW ) ) );
						$invite->set( 'user_id', $owner );
						$invite->set( 'code', md5( uniqid() ) );

						if ( ! $invite->store() ) {
							if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
								var_dump( CBTxt::T( 'AUTO_ACTION_INVITE_FAILED', ':: Action [action] :: CB Invites failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $invite->getError() ) ) );
							}

							continue;
						}

						if ( ! $invite->send() ) {
							if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
								var_dump( CBTxt::T( 'AUTO_ACTION_INVITE_SEND_FAILED', ':: Action [action] :: CB Invites failed to send. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $invite->getError() ) ) );
							}

							continue;
						}
					}
					break;
				case 2:
					$query			=	'SELECT *'
									.	"\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_invites' )
									.	"\n WHERE " . $_CB_database->NameQuote( 'to' ) . " = " . $_CB_database->Quote( $user->get( 'email' ) );
					$_CB_database->setQuery( $query );
					$invites		=	$_CB_database->loadObjectList( null, 'cbinvitesInviteTable', array( $_CB_database ) );

					/** @var cbinvitesInviteTable[] $invites */
					foreach ( $invites as $invite ) {
						$invite->accept( $user );
					}
					break;
				case 3:
					$query			=	'SELECT *'
									.	"\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_invites' )
									.	"\n WHERE ( " . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $user->get( 'id' )
									.	' OR ' . $_CB_database->NameQuote( 'user' ) . ' = ' . (int) $user->get( 'id' ) . ' )';
					$_CB_database->setQuery( $query );
					$invites		=	$_CB_database->loadObjectList( null, 'cbinvitesInviteTable', array( $_CB_database ) );

					/** @var cbinvitesInviteTable[] $invites */
					foreach ( $invites as $invite ) {
						$invite->delete();
					}
					break;
			}
		}
	}
예제 #3
0
	/**
	 * @param cbinvitesInviteTable $row
	 * @param array                $input
	 * @param UserTable            $user
	 * @param cbPluginHandler      $plugin
	 */
	static function showProductEdit( $row, $input, $user, $plugin )
	{
		global $_CB_framework, $_PLUGINS;

		cbValidator::loadValidation();

		$cbModerator		=	Application::User( (int) $user->get( 'id' ) )->isGlobalModerator();
		$pageTitle			=	( $row->get( 'id' ) ? CBTxt::T( 'MEDPR_EDIT_PRODUCT' ) : CBTxt::T( 'MEDPR_CREATE_PRODUCT' ) );

		$_CB_framework->setPageTitle( $pageTitle );
		$_CB_framework->appendPathWay( htmlspecialchars( CBTxt::T( 'MEDPR_MEDICINE_PRODUCT' ) ), $_CB_framework->userProfileUrl( $row->get( 'user', $user->get( 'id' ) ), true, 'cbinvitesTab' ) );
		$_CB_framework->appendPathWay( htmlspecialchars( $pageTitle ), $_CB_framework->pluginClassUrl( $plugin->element, true, ( $row->get( 'id' ) ? array( 'action' => 'medizd', 'func' => 'edit', 'id' => (int) $row->get( 'id' ) ) : array( 'action' => 'medizd', 'func' => 'new' ) ) ) );

		initToolTip();

		$return				=	'<div class="medizdEdit">'
							.		'<form action="' . $_CB_framework->pluginClassUrl( $plugin->element, true, array( 'action' => 'medizd', 'func' => 'save', 'id' => (int) $row->get( 'id' ) ) ) . '" method="post" enctype="multipart/form-data" name="medizdForm" id="medizdForm" class="cb_form medizdForm form-auto cbValidation">'
							.			( $pageTitle ? '<div class="invitesTitle page-header"><h3>' . $pageTitle . '</h3></div>' : null )
							.			'<div class="cbft_text cbtt_input form-group cb_form_line clearfix">'
							.				'<label for="to" class="col-sm-3 control-label">' . CBTxt::T( 'MEDPR_CODE' ) . '</label>'
							.				'<div class="cb_field col-sm-9">'
							.					$input['code']
							.					getFieldIcons( 1, 1, null)
							.				'</div>'
							.			'</div>'
							.			'<div class="cbft_text cbtt_input form-group cb_form_line clearfix">'
							.				'<label for="subject" class="col-sm-3 control-label">' . CBTxt::T( 'Name' ) . '</label>'
							.				'<div class="cb_field col-sm-9">'
							.					$input['name']
							.					getFieldIcons( 1, 1, null)
							.				'</div>'
							.			'</div>'
							.			'<div class="cbft_textarea cbtt_textarea form-group cb_form_line clearfix">'
							.				'<label for="body" class="col-sm-3 control-label">' . CBTxt::T( 'MEDPR_DESCRIPTION' ) . '</label>'
							.				'<div class="cb_field col-sm-9">'
							.					$input['description']
							.					getFieldIcons( 1, 0, null )
							.				'</div>'
							.			'</div>';

		
			$return			.=			'<div class="cbft_text cbtt_input form-group cb_form_line clearfix">'
							.				'<label for="user_id" class="col-sm-3 control-label">' . CBTxt::T( 'Category' ) . '</label>'
							.				'<div class="cb_field col-sm-9">'
							.					$input['category']
							.					getFieldIcons( 1, 1, null)
							.				'</div>'
							.			'</div>'
							.			'<div class="cbft_text cbtt_input form-group cb_form_line clearfix">'
							.				'<label for="user" class="col-sm-3 control-label">' . CBTxt::T( 'MEDPR_MANUFACTURE' ) . '</label>'
							.				'<div class="cb_field col-sm-9">'
							.					$input['proizvoditel']
							.					getFieldIcons( 1, 0, null)
							.				'</div>'
							.			'</div>'
                                                        .   '<div class="cbft_text cbtt_input form-group cb_form_line clearfix">'
							.				'<label for="user" class="col-sm-3 control-label">' . CBTxt::T( 'MEDPR_COUNTRY' ) . '</label>'
							.				'<div class="cb_field col-sm-9">'
							.					$input['country']
							.					getFieldIcons( 1, 0, null)
							.				'</div>'
							.			'</div>'
                                                        .   '<div class="cbft_text cbtt_input form-group cb_form_line clearfix">'
							.				'<label for="user" class="col-sm-3 control-label">' . CBTxt::T( 'MEDPR_PRICE' ) . '</label>'
							.				'<div class="cb_field col-sm-9">'
							.					$input['price']
							.					getFieldIcons( 1, 0, 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( 'MEDPR_UPDATE_PRODUCT' ) : CBTxt::T( 'MEDPR_SAVE_PRODUCT' ) ) ) . '" class="invitesButton invitesButtonSubmit btn btn-primary"' . cbValidator::getSubmitBtnHtmlAttributes() . ' />&nbsp;'
							.					' <input type="button" value="' . htmlspecialchars( CBTxt::T( 'Cancel' ) ) . '" class="invitesButton invitesButtonCancel btn btn-default" onclick="if ( confirm( \'' . addslashes( CBTxt::T( 'Are you sure you want to cancel? All unsaved data will be lost!' ) ) . '\' ) ) { location.href = \'' . $_CB_framework->userProfileUrl( $row->get( 'user', $user->get( 'id' ) ), false, 'cbmedizdFormTab' ) . '\'; }" />'
							.				'</div>'
							.			'</div>'
							.			cbGetSpoofInputTag( 'plugin' )
							.		'</form>'
							.	'</div>';

		echo $return;
	}
예제 #4
0
	/**
	 * @param cbinvitesInviteTable $row
	 * @param array                $input
	 * @param UserTable            $user
	 * @param cbPluginHandler      $plugin
	 */
	static function showInviteEdit( $row, $input, $user, $plugin )
	{
		global $_CB_framework, $_PLUGINS;

		cbValidator::loadValidation();

		$cbModerator		=	Application::User( (int) $user->get( 'id' ) )->isGlobalModerator();
		$pageTitle			=	( $row->get( 'to' ) ? CBTxt::T( 'Edit Invite' ) : CBTxt::T( 'Create Invite' ) );

		$_CB_framework->setPageTitle( $pageTitle );
		$_CB_framework->appendPathWay( htmlspecialchars( CBTxt::T( 'Invites' ) ), $_CB_framework->userProfileUrl( $row->get( 'user', $user->get( 'id' ) ), true, 'cbinvitesTab' ) );
		$_CB_framework->appendPathWay( htmlspecialchars( $pageTitle ), $_CB_framework->pluginClassUrl( $plugin->element, true, ( $row->get( 'id' ) ? array( 'action' => 'invites', 'func' => 'edit', 'id' => (int) $row->get( 'id' ) ) : array( 'action' => 'invites', 'func' => 'new' ) ) ) );

		initToolTip();

		$return				=	'<div class="invitesEdit">'
							.		'<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="invitesForm" id="invitesForm" class="cb_form invitesForm form-auto cbValidation">'
							.			( $pageTitle ? '<div class="invitesTitle page-header"><h3>' . $pageTitle . '</h3></div>' : null )
							.			'<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">'
							.					$input['to']
							.					getFieldIcons( 1, 1, null, ( $plugin->params->get( 'invite_multiple', 1 ) ? CBTxt::T( 'Input invite email to address. Separate multiple email addresses with a comma.' ) : CBTxt::T( 'Input invite email to address.' ) ) )
							.				'</div>'
							.			'</div>'
							.			'<div class="cbft_text cbtt_input form-group cb_form_line clearfix">'
							.				'<label for="subject" class="col-sm-3 control-label">' . CBTxt::T( 'Subject' ) . '</label>'
							.				'<div class="cb_field col-sm-9">'
							.					$input['subject']
							.					getFieldIcons( 1, 0, null, CBTxt::T( 'Input invite email subject; if left blank a subject will be applied.' ) )
							.				'</div>'
							.			'</div>'
							.			'<div class="cbft_textarea cbtt_textarea form-group cb_form_line clearfix">'
							.				'<label for="body" class="col-sm-3 control-label">' . CBTxt::T( 'Body' ) . '</label>'
							.				'<div class="cb_field col-sm-9">'
							.					$input['body']
							.					getFieldIcons( 1, 0, null, CBTxt::T( 'Optionally input private message to include with invite email.' ) )
							.				'</div>'
							.			'</div>';

		if ( $cbModerator ) {
			$return			.=			'<div class="cbft_text cbtt_input form-group cb_form_line clearfix">'
							.				'<label for="user_id" class="col-sm-3 control-label">' . CBTxt::T( 'Owner' ) . '</label>'
							.				'<div class="cb_field col-sm-9">'
							.					$input['user_id']
							.					getFieldIcons( 1, 1, null, CBTxt::T( 'Input owner of invite as single integer user_id. This is the user who sent the invite.' ) )
							.				'</div>'
							.			'</div>'
							.			'<div class="cbft_text cbtt_input form-group cb_form_line clearfix">'
							.				'<label for="user" class="col-sm-3 control-label">' . CBTxt::T( 'User' ) . '</label>'
							.				'<div class="cb_field col-sm-9">'
							.					$input['user']
							.					getFieldIcons( 1, 0, null, CBTxt::T( 'Optionally input user of invite as single integer user_id. This is the user who accepted the invite.' ) )
							.				'</div>'
							.			'</div>';
		}

		if ( $plugin->params->get( 'invite_captcha', 0 ) && ( ! $cbModerator ) ) {
			$_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::Th( '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( 1, 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( 'Send Invite' ) ) ) . '" class="invitesButton invitesButtonSubmit btn btn-primary"' . cbValidator::getSubmitBtnHtmlAttributes() . ' />&nbsp;'
							.					' <input type="button" value="' . htmlspecialchars( CBTxt::T( 'Cancel' ) ) . '" class="invitesButton invitesButtonCancel btn btn-default" onclick="if ( confirm( \'' . addslashes( CBTxt::T( 'Are you sure you want to cancel? All unsaved data will be lost!' ) ) . '\' ) ) { location.href = \'' . $_CB_framework->userProfileUrl( $row->get( 'user', $user->get( 'id' ) ), false, 'cbinvitesTab' ) . '\'; }" />'
							.				'</div>'
							.			'</div>'
							.			cbGetSpoofInputTag( 'plugin' )
							.		'</form>'
							.	'</div>';

		echo $return;
	}
예제 #5
0
	/**
	 * @param FieldTable $field
	 * @param UserTable  $user
	 * @param string     $columnName
	 * @param string     $value
	 * @param array      $postdata
	 * @param string     $reason
	 * @return bool
	 */
	public function validate( &$field, &$user, $columnName, &$value, &$postdata, $reason )
	{
		$validated				=	parent::validate( $field, $user, $columnName, $value, $postdata, $reason );

		if ( $validated ) {
			if ( ( $user->get( $columnName ) != $value ) && $value ) {
				$invite			=	new cbinvitesInviteTable();

				$invite->load( array( 'code' => $value ) );

				if ( ! $invite->get( 'id' ) ) {
					$this->_setValidationError( $field, $user, $reason, CBTxt::T( 'Invite code not valid.' ) );

					$validated	=	false;
				} elseif ( $invite->isAccepted() && ( $user->get( 'id' ) != $invite->get( 'user' ) ) ) {
					$this->_setValidationError( $field, $user, $reason, CBTxt::T( 'Invite code already used.' ) );

					$validated	=	false;
				}
			}
		}

		return $validated;
	}