Esempio n. 1
0
	private function saveAutoEdit( $id, $task, $user, $plugin ) {
		$row		=	cbgjAutoData::getAutos( null, array( 'id', '=', (int) $id ), null, null, false );

		$row->set( 'published', (int) cbgjClass::getCleanParam( true, 'published', $row->get( 'published' ) ) );
		$row->set( 'title', cbgjClass::getCleanParam( true, 'title', $row->get( 'title' ) ) );
		$row->set( 'description', cbgjClass::getCleanParam( true, 'description', $row->get( 'description' ) ) );
		$row->set( 'trigger', str_replace( ' ', '', cbgjClass::getCleanParam( true, 'trigger', $row->get( 'trigger' ) ) ) );
		$row->set( 'object', (int) cbgjClass::getCleanParam( true, 'object', $row->get( 'object' ) ) );

		if ( $row->get( 'object' ) == 3 ) {
			$row->set( 'variable', (int) cbgjClass::getCleanParam( true, 'variable_user', $row->get( 'variable' ) ) );
		} elseif ( $row->get( 'object' ) == 2 ) {
			$row->set( 'variable', null );
		} elseif ( $row->get( 'object' ) == 1 ) {
			$row->set( 'variable', (int) cbgjClass::getCleanParam( true, 'variable', $row->get( 'variable' ) ) );
		}

		$row->set( 'access', cbgjClass::getCleanParam( true, 'access', $row->get( 'access' ) ) );
		$row->set( 'exclude', cbgjClass::getCleanParam( true, 'exclude', $row->get( 'exclude' ) ) );
		$row->set( 'ordering', (int) cbgjClass::getCleanParam( true, 'ordering', $row->get( 'ordering' ) ) );

		if ( $row->get( 'exclude' ) ) {
			$exclude	=	explode( ',', $row->get( 'exclude' ) );

			cbArrayToInts( $exclude );

			$row->set( 'exclude', implode( ',', $exclude ) );
		}

		$row->setParams( $_POST['params'] );

		if ( $row->get( 'trigger' ) == '' ) {
			$row->set( '_error', CBTxt::T( 'Trigger not specified!' ) );
		} elseif ( $row->get( 'access' ) == '' ) {
			$row->set( '_error', CBTxt::T( 'Access not specified!' ) );
		} elseif ( $row->get( 'object' ) ) {
			if ( $row->get( 'object' ) == 3 ) {
				if ( ! $row->get( 'variable' ) ) {
					$row->set( '_error', CBTxt::T( 'Specific user not specified!' ) );
				}
			} elseif ( $row->get( 'object' ) == 1 ) {
				if ( ! $row->get( 'variable' ) ) {
					$row->set( '_error', CBTxt::T( 'User variable not specified!' ) );
				}
			}
		} else {
			$params		=	$row->getParams();

			if ( $params->get( 'auto', null ) == '' ) {
				$row->set( '_error', CBTxt::T( 'Auto not specified!' ) );
			} else {
				if ( $params->get( 'auto', null ) == 1 ) {
					if ( $params->get( 'groups', null ) == '' ) {
						$row->set( '_error', CBTxt::T( 'Groups not specified!' ) );
					} elseif ( $params->get( 'status', null ) == '' ) {
						$row->set( '_error', CBTxt::T( 'Status not specified!' ) );
					}
				} elseif ( $params->get( 'auto', null ) == 2 ) {
					if ( $params->get( 'category', null ) == '' ) {
						$row->set( '_error', CBTxt::T( 'Category not specified!' ) );
					} elseif ( $params->get( 'grp_name', null ) == '' ) {
						$row->set( '_error', CBTxt::T( 'Group Name not specified!' ) );
					} elseif ( $params->get( 'type', null ) == '' ) {
						$row->set( '_error', CBTxt::T( 'Type not specified!' ) );
					} elseif ( $params->get( 'category', null ) == -1 ) {
						if ( $params->get( 'cat_name', null ) == '' ) {
							$row->set( '_error', CBTxt::T( 'Category Name not specified!' ) );
						}
					}
				} elseif ( $params->get( 'auto', null ) == 3 ) {
					if ( $params->get( 'cat_name', null ) == '' ) {
						$row->set( '_error', CBTxt::T( 'Category Name not specified!' ) );
					} elseif ( $params->get( 'types', null ) == '' ) {
						$row->set( '_error', CBTxt::T( 'Types not specified!' ) );
					}
				} elseif ( $params->get( 'auto', null ) == 4 ) {
					if ( $params->get( 'groups', null ) == '' ) {
						$row->set( '_error', CBTxt::T( 'Groups not specified!' ) );
					}
				}
			}
		}

		$row->setFields( $_POST['fields'] );
		$row->setOperators( $_POST['operators'] );
		$row->setValues( $_POST['values'] );

		if ( $row->getError() || ( ! $row->store() ) ) {
			return $this->getAutoEdit( $id, $user, $plugin, CBTxt::P( 'Auto failed to save! Error: [error]', array( '[error]' => $row->getError() ) ) );
		}

		if ( in_array( $task, array( 'apply', 'auto_apply' ) ) ) {
			cbgjClass::getPluginURL( array( 'plugin', 'auto_edit', (int) $row->get( 'id' ) ), CBTxt::T( 'Auto saved successfully!' ), false, true );
		} else {
			cbgjClass::getPluginURL( array( 'plugin', 'auto' ), CBTxt::T( 'Auto saved successfully!' ), false, true );
		}
	}
Esempio n. 2
0
	static public function stateForum( $row, $user, $plugin ) {
		global $_CB_database;

		$params				=	$row->getParams();
		$forumId			=	$params->get( 'forum_id', null );

		if ( $forumId ) {
			if ( method_exists( $row, 'getCategory' ) ) {
				$authorized	=	cbgjClass::getAuthorization( $row->getCategory(), $row, $user );
			} else {
				$authorized	=	cbgjClass::getAuthorization( $row, null, $user );
			}

			$forumShow		=	(int) cbgjClass::getCleanParam( ( $plugin->params->get( 'forum_show_config', 1 ) || cbgjClass::hasAccess( 'usr_mod', $authorized ) ), 'forum_show', $params->get( 'forum_show', $plugin->params->get( 'forum_show', 1 ) ) );

			$query			=	'UPDATE ' . $_CB_database->NameQuote( '#__kunena_categories' )
							.	"\n SET " . $_CB_database->NameQuote( 'published' ) . " = " . (int) ( ! $forumShow ? 0 : $row->get( 'published' ) )
							.	"\n WHERE " . $_CB_database->NameQuote( 'id' ) . " = " . (int) $forumId;
			$_CB_database->setQuery( $query );
			$_CB_database->query();
		}
	}
	/**
	 * Called at each change of user subscription state due to a plan activation or deactivation
	 *
	 * @param  UserTable        $user
	 * @param  string           $status
	 * @param  int              $planId
	 * @param  int              $replacedPlanId
	 * @param  ParamsInterface  $integrationParams
	 * @param  string           $cause              'PaidSubscription' (first activation only), 'SubscriptionActivated' (renewals, cancellation reversals), 'SubscriptionDeactivated', 'Denied'
	 * @param  string           $reason             'N' new subscription, 'R' renewal, 'U'=update )
	 * @param  int              $now                Unix time
	 */
	public function onCPayUserStateChange( &$user, $status, /** @noinspection PhpUnusedParameterInspection */ $planId, /** @noinspection PhpUnusedParameterInspection */ $replacedPlanId, &$integrationParams, /** @noinspection PhpUnusedParameterInspection */ $cause, /** @noinspection PhpUnusedParameterInspection */ $reason, /** @noinspection PhpUnusedParameterInspection */ $now ) {
		global $_CB_framework;

		if ( ! is_object( $user ) ) {
			return;
		}

		$api											=	$_CB_framework->getCfg( 'absolute_path' ) . '/components/com_comprofiler/plugin/user/plug_cbgroupjive/cbgroupjive.class.php';

		if ( ! file_exists( $api ) ) {
			return;
		}

		/** @noinspection PhpIncludeInspection */
		require_once( $api );

		$gj_plugin										=	cbgjClass::getPlugin();
		$cbUser											=	CBuser::getInstance( $user->id );

		if ( ! $cbUser ) {
			$cbUser										=	$cbUser->getInstance( null );
		}

		for ( $i = 1; $i <= 5; $i++ ) {
			if ( $status == 'A' ) {
				if ( ( cbgjClass::getCleanParam( true, 'cbgj_auto_type' . $i, null, null, $integrationParams ) == 3 ) && cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) ) {
					$parent								=	(int) cbgjClass::getCleanParam( true, 'cbgj_auto_cat_parent' . $i, '0', null, $integrationParams );
					$name								=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) );

					if ( cbgjClass::getCleanParam( true, 'cbgj_auto_unique' . $i, 1, null, $integrationParams ) ) {
						$where							=	array( array( 'user_id', '=', $user->id ), array( 'name', '=', $name ), array( 'parent', '=', $parent ) );
					} else {
						$where							=	array( array( 'name', '=', $name ), array( 'parent', '=', $parent ) );
					}

					$row								=	cbgjData::getCategories( null, null, $where, null, null, false );

					if ( ! $row->id ) {
						$category_editor				=	$gj_plugin->params->get( 'category_editor', 1 );
						$types							=	cbgjClass::getCleanParam( true, 'cbgj_auto_cat_types' . $i, '1|*|2|*|3', null, $integrationParams );

						$row->published					=	1;
						$row->parent					=	$parent;
						$row->user_id					=	(int) $user->id;
						$row->name						=	$name;

						if ( ( $category_editor == 2 ) || ( $category_editor == 3 ) ) {
							$row->description			=	$cbUser->replaceUserVars( cbgjClass::getHTMLCleanParam( true, 'cbgj_auto_desc' . $i, null, null, $integrationParams ) );
						} else {
							$row->description			=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_desc' . $i, null, null, $integrationParams ) );
						}

						$row->access					=	(int) $gj_plugin->params->get( 'category_access_default', -2 );
						$row->types						=	( $types ? $types : $gj_plugin->params->get( 'category_types_default', '1|*|2|*|3' ) );
						$row->create					=	(int) $gj_plugin->params->get( 'category_create_default', 1 );
						$row->create_access				=	(int) $gj_plugin->params->get( 'category_createaccess_default', -1 );
						$row->nested					=	(int) $gj_plugin->params->get( 'category_nested_default', 1 );
						$row->nested_access				=	(int) $gj_plugin->params->get( 'category_nestedaccess_default', -1 );
						$row->date						=	date( 'Y-m-d H:i:s' );
						$row->ordering					=	99999;

						$row->store();
					}
				} elseif ( ( cbgjClass::getCleanParam( true, 'cbgj_auto_type' . $i, null, null, $integrationParams ) == 2 ) && cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat' . $i, null, null, $integrationParams ) && cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) ) {
					if ( ( cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat' . $i, null, null, $integrationParams ) == -1 ) && cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat_name' . $i, null, null, $integrationParams ) ) {
						$parent							=	(int) cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat_parent' . $i, '0', null, $integrationParams );
						$name							=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat_name' . $i, null, null, $integrationParams ) );

						if ( cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat_unique' . $i, 1, null, $integrationParams ) ) {
							$where						=	array( array( 'user_id', '=', $user->id ), array( 'name', '=', $name ), array( 'parent', '=', $parent ) );
						} else {
							$where						=	array( array( 'name', '=', $name ), array( 'parent', '=', $parent ) );
						}

						$category						=	cbgjData::getCategories( null, null, $where, null, null, false );

						if ( ! $category->id ) {
							$category_editor			=	$gj_plugin->params->get( 'category_editor', 1 );
							$types						=	cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat_types' . $i, '1|*|2|*|3', null, $integrationParams );

							$category->published		=	1;
							$category->parent			=	$parent;
							$category->user_id			=	(int) $user->id;
							$category->name				=	$name;

							if ( ( $category_editor == 2 ) || ( $category_editor == 3 ) ) {
								$category->description	=	$cbUser->replaceUserVars( cbgjClass::getHTMLCleanParam( true, 'cbgj_auto_grp_cat_desc' . $i, null, null, $integrationParams ) );
							} else {
								$category->description	=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat_desc' . $i, null, null, $integrationParams ) );
							}

							$category->access			=	(int) $gj_plugin->params->get( 'category_access_default', -2 );
							$category->types			=	( $types ? $types : $gj_plugin->params->get( 'category_types_default', '1|*|2|*|3' ) );
							$category->create			=	(int) $gj_plugin->params->get( 'category_create_default', 1 );
							$category->create_access	=	(int) $gj_plugin->params->get( 'category_createaccess_default', -1 );
							$category->nested			=	(int) $gj_plugin->params->get( 'category_nested_default', 1 );
							$category->nested_access	=	(int) $gj_plugin->params->get( 'category_nestedaccess_default', -1 );
							$category->date				=	date( 'Y-m-d H:i:s' );
							$category->ordering			=	99999;

							$category->store();
						}
					} else {
						$category						=	cbgjData::getCategories( null, null, array( 'id', '=', cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat' . $i, null, null, $integrationParams ) ), null, null, false );
					}

					if ( $category->id ) {
						$parent							=	(int) cbgjClass::getCleanParam( true, 'cbgj_auto_grp_parent' . $i, '0', null, $integrationParams );
						$name							=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) );
						$join							=	false;

						if ( cbgjClass::getCleanParam( true, 'cbgj_auto_unique' . $i, 1, null, $integrationParams ) ) {
							$where						=	array( array( 'category', '=', $category->id ), array( 'user_id', '=', $user->id ), array( 'name', '=', $name ), array( 'parent', '=', $parent ) );
						} else {
							$where						=	array( array( 'category', '=', $category->id ), array( 'name', '=', $name ), array( 'parent', '=', $parent ) );

							if ( cbgjClass::getCleanParam( true, 'cbgj_auto_grp_autojoin' . $i, 1, null, $integrationParams ) ) {
								$join					=	true;
							}
						}

						$row							=	cbgjData::getGroups( null, null, $where, null, null, false );

						if ( ! $row->id ) {
							$group_editor				=	$gj_plugin->params->get( 'group_editor', 1 );
							$type						=	cbgjClass::getCleanParam( true, 'cbgj_auto_grp_type' . $i, 1, null, $integrationParams );

							$row->published				=	1;
							$row->category				=	(int) $category->id;
							$row->parent				=	$parent;
							$row->user_id				=	(int) $user->id;
							$row->name					=	$name;

							if ( ( $group_editor == 2 ) || ( $group_editor == 3 ) ) {
								$row->description		=	$cbUser->replaceUserVars( cbgjClass::getHTMLCleanParam( true, 'cbgj_auto_desc' . $i, null, null, $integrationParams ) );
							} else {
								$row->description		=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_desc' . $i, null, null, $integrationParams ) );
							}

							$row->access				=	(int) $gj_plugin->params->get( 'group_access_default', -2 );
							$row->type					=	(int) ( $type ? $type : $gj_plugin->params->get( 'group_type_default', 1 ) );
							$row->nested				=	(int) $gj_plugin->params->get( 'group_nested_default', 1 );
							$row->nested_access			=	(int) $gj_plugin->params->get( 'group_nestedaccess_default', -1 );
							$row->date					=	date( 'Y-m-d H:i:s' );
							$row->ordering				=	1;

							if ( $row->store() ) {
								$row->storeOwner( $row->user_id );
							}
						} elseif ( $join ) {
							$usr						=	cbgjData::getUsers( null, null, array( array( 'group', '=', $row->id ), array( 'user_id', '=', $user->id ) ), null, null, false );

							if ( ! $usr->id ) {
								$usr->user_id			=	(int) $user->id;
								$usr->group				=	(int) $row->id;
								$usr->date				=	date( 'Y-m-d H:i:s' );
								$usr->status			=	(int) cbgjClass::getCleanParam( true, 'cbgj_auto_grp_usr_status' . $i, 1, null, $integrationParams );

								if ( $usr->store() ) {
									if ( $usr->status == 4 ) {
										$row->storeOwner( $usr->user_id );
									}
								}
							}
						}
					}
				} elseif ( ( cbgjClass::getCleanParam( true, 'cbgj_auto_type' . $i, null, null, $integrationParams ) == 1 ) && cbgjClass::getCleanParam( true, 'cbgj_auto_usr_groups' . $i, null, null, $integrationParams ) ) {
					$groups								=	cbgjClass::getCleanParam( true, 'cbgj_auto_usr_groups' . $i, null, null, $integrationParams );

					if ( $groups ) {
						$groups							=	explode( '|*|', $groups );

						cbArrayToInts( $groups );
					}

					if ( $groups ) foreach ( $groups as $group_id ) {
						$group							=	cbgjData::getGroups( null, null, array( 'id', '=', $group_id ), null, null, false );

						if ( $group->id ) {
							$row						=	cbgjData::getUsers( null, null, array( array( 'group', '=', $group->id ), array( 'user_id', '=', $user->id ) ), null, null, false );

							if ( ! $row->id ) {
								$row->user_id			=	(int) $user->id;
								$row->group				=	(int) $group->id;
								$row->date				=	date( 'Y-m-d H:i:s' );
								$row->status			=	(int) cbgjClass::getCleanParam( true, 'cbgj_auto_usr_status' . $i, 1, null, $integrationParams );

								if ( $row->store() ) {
									if ( $row->status == 4 ) {
										$group->storeOwner( $row->user_id);
									}
								}
							}
						}
					}
				}
			} elseif ( cbgjClass::getCleanParam( true, 'cbgj_auto_remove' . $i, null, null, $integrationParams ) ) {
				if ( ( cbgjClass::getCleanParam( true, 'cbgj_auto_type' . $i, null, null, $integrationParams ) == 3 ) && cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) ) {
					$name								=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) );

					if ( cbgjClass::getCleanParam( true, 'cbgj_auto_unique' . $i, 1, null, $integrationParams ) ) {
						$where							=	array( array( 'user_id', '=', $user->id ), array( 'name', '=', $name ) );
					} else {
						$where							=	array( 'name', '=', $name );
					}

					$row								=	cbgjData::getCategories( null, null, $where, null, null, false );

					if ( $row->id ) {
						$row->deleteAll();
					}
				} elseif ( ( cbgjClass::getCleanParam( true, 'cbgj_auto_type' . $i, null, null, $integrationParams ) == 2 ) && cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat' . $i, null, null, $integrationParams ) && cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) ) {
					$name								=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) );

					if ( cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat' . $i, null, null, $integrationParams ) == -1 ) {
						if ( cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat_unique' . $i, 1, null, $integrationParams ) ) {
							$where						=	array( array( 'user_id', '=', $user->id ), array( 'name', '=', $name ) );
						} else {
							$where						=	array( 'name', '=', $name );
						}
					} else {
						$category						=	cbgjData::getCategories( null, null, array( 'id', '=', cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat' . $i, null, null, $integrationParams ) ), null, null, false );

						if ( cbgjClass::getCleanParam( true, 'cbgj_auto_unique' . $i, 1, null, $integrationParams ) ) {
							$where						=	array( array( 'category', '=', $category->id ), array( 'user_id', '=', $user->id ), array( 'name', '=', $name ) );
						} else {
							$where						=	array( array( 'category', '=', $category->id ), array( 'name', '=', $name ) );
						}
					}

					$row								=	cbgjData::getGroups( null, null, $where, null, null, false );

					if ( $row->id ) {
						$row->deleteAll();
					}
				} elseif ( ( cbgjClass::getCleanParam( true, 'cbgj_auto_type' . $i, null, null, $integrationParams ) == 1 ) && cbgjClass::getCleanParam( true, 'cbgj_auto_usr_groups' . $i, null, null, $integrationParams ) ) {
					$groups								=	cbgjClass::getCleanParam( true, 'cbgj_auto_usr_groups' . $i, null, null, $integrationParams );

					if ( $groups ) {
						$groups							=	explode( '|*|', $groups );

						cbArrayToInts( $groups );
					}

					if ( $groups ) foreach ( $groups as $group_id ) {
						$group							=	cbgjData::getGroups( null, null, array( 'id', '=', $group_id ), null, null, false );

						if ( $group->id ) {
							$row						=	cbgjData::getUsers( null, null, array( array( 'group', '=', $group->id ), array( 'user_id', '=', $user->id ) ), null, null, false );

							if ( $row->id ) {
								$row->deleteAll();
							}
						}
					}
				}
			}
		}
	}
	/**
	 * saves users notifications
	 *
	 * @param int $catid
	 * @param int $grpid
	 * @param moscomprofilerUser $user
	 * @param object $plugin
	 * @param boolean $silent
	 * @return boolean
	 */
	static public function saveNotifications( $catid, $grpid, $user, $plugin, $silent = true ) {
		$category						=	cbgjData::getCategories( null, array( 'id', '=', (int) $catid ), null, null, false );
		$group							=	cbgjData::getGroups( null, array( 'id', '=', (int) $grpid ), null, null, false );

		if ( ( ! $category->get( 'id' ) ) && $group->get( 'id' ) ) {
			$category					=	$group->getCategory();
		}

		$authorized						=	cbgjClass::getAuthorization( $category, $group, $user );

		if ( cbgjClass::hasAccess( 'usr_notifications', $authorized ) ) {
			$categoryApprove			=	$plugin->params->get( 'category_approve', 0 );
			$groupApprove				=	$plugin->params->get( 'group_approve', 0 );

			if ( cbgjClass::hasAccess( 'gen_usr_notifications', $authorized ) ) {
				$generalNotifications	=	cbgjData::getNotifications( null, array( array( 'type', '=', 'general' ), array( 'user_id', '=', (int) $user->id ) ), null, null, false );

				$generalNotifications->set( 'user_id', (int) $user->id );
				$generalNotifications->set( 'type', 'general' );
				$generalNotifications->set( 'item', 0 );

				if ( $generalNotifications->getError() || ( ! $generalNotifications->store() ) ) {
					if ( ! $silent ) {
						cbgjClass::getPluginURL( array( 'notifications', 'show', (int) $category->get( 'id' ), (int) $group->get( 'id' ) ), CBTxt::P( 'General notifications failed to save! Error: [error]', array( '[error]' => $generalNotifications->getError() ) ), false, true, null, false, false, true );
					}

					return false;
				}

				$generalParams			=	$generalNotifications->getParams();
				$generalCleanParams		=	new cbParamsBase( null );

				$generalCleanParams->set( 'general_categorynew', ( (int) ( cbgjClass::hasAccess( 'usr_mod', $authorized ) ? cbgjClass::getCleanParam( true, 'general_categorynew', $generalParams->get( 'general_categorynew', $plugin->params->get( 'notifications_general_categorynew', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$generalCleanParams->set( 'general_categoryapprove', ( (int) ( cbgjClass::hasAccess( 'usr_mod', $authorized ) && $categoryApprove ? cbgjClass::getCleanParam( true, 'general_categoryapprove', $generalParams->get( 'general_categoryapprove', $plugin->params->get( 'notifications_general_categoryapprove', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$generalCleanParams->set( 'general_categoryupdate', ( (int) ( cbgjClass::hasAccess( 'usr_mod', $authorized ) ? cbgjClass::getCleanParam( true, 'general_categoryupdate', $generalParams->get( 'general_categoryupdate', $plugin->params->get( 'notifications_general_categoryupdate', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$generalCleanParams->set( 'general_categorydelete', ( (int) ( cbgjClass::hasAccess( 'usr_mod', $authorized ) ? cbgjClass::getCleanParam( true, 'general_categorydelete', $generalParams->get( 'general_categorydelete', $plugin->params->get( 'notifications_general_categorydelete', 0 ) ) ) : 0 ) ? 1 : 0 ) );

				if ( $generalNotifications->getError() || ( ! $generalNotifications->storeParams( $generalCleanParams ) ) ) {
					if ( ! $silent ) {
						cbgjClass::getPluginURL( array( 'notifications', 'show', (int) $category->get( 'id' ), (int) $group->get( 'id' ) ), CBTxt::P( 'General notifications failed to save! Error: [error]', array( '[error]' => $generalNotifications->getError() ) ), false, true, null, false, false, true );
					}

					return false;
				}
			}

			if ( cbgjClass::hasAccess( 'cat_usr_notifications', $authorized ) ) {
				$categoryNotifications	=	cbgjData::getNotifications( null, array( array( 'type', '=', 'category' ), array( 'item', '=', (int) $catid ), array( 'user_id', '=', (int) $user->id ) ), null, null, false );

				$categoryNotifications->set( 'user_id', (int) $user->id );
				$categoryNotifications->set( 'type', 'category' );
				$categoryNotifications->set( 'item', (int) $category->get( 'id' ) );

				if ( $categoryNotifications->getError() || ( ! $categoryNotifications->store() ) ) {
					if ( ! $silent ) {
						cbgjClass::getPluginURL( array( 'notifications', 'show', (int) $category->get( 'id' ), (int) $group->get( 'id' ) ), CBTxt::P( '[category] notifications failed to save! Error: [error]', array( '[category]' => cbgjClass::getOverride( 'category' ), '[error]' => $categoryNotifications->getError() ) ), false, true, null, false, false, true );
					}

					return false;
				}

				$categoryParams			=	$categoryNotifications->getParams();
				$categoryCleanParams	=	new cbParamsBase( null );

				$categoryCleanParams->set( 'category_nestednew', ( (int) ( cbgjClass::hasAccess( array( 'mod_lvl1', 'cat_nested' ), $authorized, true ) ? cbgjClass::getCleanParam( true, 'category_nestednew', $categoryParams->get( 'category_nestednew', $plugin->params->get( 'notifications_category_nestednew', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$categoryCleanParams->set( 'category_nestedapprove', ( (int) ( cbgjClass::hasAccess( array( 'mod_lvl1', 'cat_nested' ), $authorized, true ) && $categoryApprove ? cbgjClass::getCleanParam( true, 'category_nestedapprove', $categoryParams->get( 'category_nestedapprove', $plugin->params->get( 'notifications_category_nestedapprove', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$categoryCleanParams->set( 'category_nestedupdate', ( (int) ( cbgjClass::hasAccess( array( 'mod_lvl1', 'cat_nested' ), $authorized, true ) ? cbgjClass::getCleanParam( true, 'category_nestedupdate', $categoryParams->get( 'category_nestedupdate', $plugin->params->get( 'notifications_category_nestedupdate', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$categoryCleanParams->set( 'category_nesteddelete', ( (int) ( cbgjClass::hasAccess( array( 'mod_lvl1', 'cat_nested' ), $authorized, true ) ? cbgjClass::getCleanParam( true, 'category_nesteddelete', $categoryParams->get( 'category_nesteddelete', $plugin->params->get( 'notifications_category_nesteddelete', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$categoryCleanParams->set( 'category_groupnew', ( (int) ( cbgjClass::hasAccess( array( 'mod_lvl1', 'grp_create' ), $authorized, true ) ? cbgjClass::getCleanParam( true, 'category_groupnew', $categoryParams->get( 'category_groupnew', $plugin->params->get( 'notifications_category_groupnew', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$categoryCleanParams->set( 'category_groupapprove', ( (int) ( cbgjClass::hasAccess( array( 'mod_lvl1', 'grp_create' ), $authorized, true ) && $groupApprove ? cbgjClass::getCleanParam( true, 'category_groupapprove', $categoryParams->get( 'category_groupapprove', $plugin->params->get( 'notifications_category_groupapprove', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$categoryCleanParams->set( 'category_groupupdate', ( (int) ( cbgjClass::hasAccess( array( 'mod_lvl1', 'grp_create' ), $authorized, true ) ? cbgjClass::getCleanParam( true, 'category_groupupdate', $categoryParams->get( 'category_groupupdate', $plugin->params->get( 'notifications_category_groupupdate', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$categoryCleanParams->set( 'category_groupdelete', ( (int) ( cbgjClass::hasAccess( array( 'mod_lvl1', 'grp_create' ), $authorized, true ) ? cbgjClass::getCleanParam( true, 'category_groupdelete', $categoryParams->get( 'category_groupdelete', $plugin->params->get( 'notifications_category_groupdelete', 0 ) ) ) : 0 ) ? 1 : 0 ) );

				if ( $categoryNotifications->getError() || ( ! $categoryNotifications->storeParams( $categoryCleanParams ) ) ) {
					if ( ! $silent ) {
						cbgjClass::getPluginURL( array( 'notifications', 'show', (int) $category->get( 'id' ), (int) $group->get( 'id' ) ), CBTxt::P( '[category] notifications failed to save! Error: [error]', array( '[category]' => cbgjClass::getOverride( 'category' ), '[error]' => $categoryNotifications->getError() ) ), false, true, null, false, false, true );
					}

					return false;
				}
			}

			if ( cbgjClass::hasAccess( 'grp_usr_notifications', $authorized ) ) {
				$groupNotifications		=	cbgjData::getNotifications( null, array( array( 'type', '=', 'group' ), array( 'item', '=', (int) $grpid ), array( 'user_id', '=', (int) $user->id ) ), null, null, false );

				$groupNotifications->set( 'user_id', (int) $user->id );
				$groupNotifications->set( 'type', 'group' );
				$groupNotifications->set( 'item', (int) $group->get( 'id' ) );

				if ( $groupNotifications->getError() || ( ! $groupNotifications->store() ) ) {
					if ( ! $silent ) {
						cbgjClass::getPluginURL( array( 'notifications', 'show', (int) $category->get( 'id' ), (int) $group->get( 'id' ) ), CBTxt::P( '[group] notifications failed to save! Error: [error]', array( '[group]' => cbgjClass::getOverride( 'category' ), '[error]' => $groupNotifications->getError() ) ), false, true, null, false, false, true );
					}

					return false;
				}

				$groupParams			=	$groupNotifications->getParams();
				$groupCleanParams		=	new cbParamsBase( null );

				$groupCleanParams->set( 'group_nestednew', ( (int) ( cbgjClass::hasAccess( array( 'mod_lvl2', 'grp_nested' ), $authorized, true ) ? cbgjClass::getCleanParam( true, 'group_nestednew', $groupParams->get( 'group_nestednew', $plugin->params->get( 'notifications_group_nestednew', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$groupCleanParams->set( 'group_nestedapprove', ( (int) ( cbgjClass::hasAccess( array( 'mod_lvl2', 'grp_nested' ), $authorized, true ) && $groupApprove ? cbgjClass::getCleanParam( true, 'group_nestedapprove', $groupParams->get( 'group_nestedapprove', $plugin->params->get( 'notifications_group_nestedapprove', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$groupCleanParams->set( 'group_nestedupdate', ( (int) ( cbgjClass::hasAccess( array( 'mod_lvl2', 'grp_nested' ), $authorized, true ) ? cbgjClass::getCleanParam( true, 'group_nestedupdate', $groupParams->get( 'group_nestedupdate', $plugin->params->get( 'notifications_group_nestedupdate', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$groupCleanParams->set( 'group_nesteddelete', ( (int) ( cbgjClass::hasAccess( array( 'mod_lvl2', 'grp_nested' ), $authorized, true ) ? cbgjClass::getCleanParam( true, 'group_nesteddelete', $groupParams->get( 'group_nesteddelete', $plugin->params->get( 'notifications_group_nesteddelete', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$groupCleanParams->set( 'group_userjoin', ( (int) ( cbgjClass::hasAccess( 'mod_lvl4', $authorized ) ? cbgjClass::getCleanParam( true, 'group_userjoin', $groupParams->get( 'group_userjoin', $plugin->params->get( 'notifications_group_userjoin', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$groupCleanParams->set( 'group_userleave', ( (int) ( cbgjClass::hasAccess( 'mod_lvl4', $authorized ) ? cbgjClass::getCleanParam( true, 'group_userleave', $groupParams->get( 'group_userleave', $plugin->params->get( 'notifications_group_userleave', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$groupCleanParams->set( 'group_userinvite', ( (int) ( cbgjClass::hasAccess( 'mod_lvl2', $authorized ) ? cbgjClass::getCleanParam( true, 'group_userinvite', $groupParams->get( 'group_userinvite', $plugin->params->get( 'notifications_group_userinvite', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$groupCleanParams->set( 'group_userapprove', ( (int) ( cbgjClass::hasAccess( 'mod_lvl4', $authorized ) ? cbgjClass::getCleanParam( true, 'group_userapprove', $groupParams->get( 'group_userapprove', $plugin->params->get( 'notifications_group_userapprove', 0 ) ) ) : 0 ) ? 1 : 0 ) );
				$groupCleanParams->set( 'group_inviteaccept', ( (int) ( cbgjClass::hasAccess( 'grp_invite', $authorized ) ? cbgjClass::getCleanParam( true, 'group_inviteaccept', $groupParams->get( 'group_inviteaccept', $plugin->params->get( 'notifications_group_inviteaccept', 0 ) ) ) : 0 ) ? 1 : 0 ) );

				if ( $groupNotifications->getError() || ( ! $groupNotifications->storeParams( $groupCleanParams ) ) ) {
					if ( ! $silent ) {
						cbgjClass::getPluginURL( array( 'notifications', 'show', (int) $category->get( 'id' ), (int) $group->get( 'id' ) ), CBTxt::P( '[group] notifications failed to save! Error: [error]', array( '[group]' => cbgjClass::getOverride( 'category' ), '[error]' => $groupNotifications->getError() ) ), false, true, null, false, false, true );
						return false;
					}

					return false;
				}
			}

			if ( ! $silent ) {
				cbgjClass::getPluginURL( array( 'notifications', 'show', (int) $category->get( 'id' ), (int) $group->get( 'id' ) ), CBTxt::T( 'Notifications saved successfully!' ), false, true, null, false, false, true );
			}

			return true;
		} else {
			if ( ! $silent ) {
				cbgjClass::getPluginURL( array( 'overview' ), CBTxt::T( 'Not authorized.' ), false, true, 'error' );
			}

			return false;
		}
	}
Esempio n. 5
0
	static public function stateForum( $row, $user, $plugin ) {
		if ( ! class_exists( 'KunenaForumCategoryHelper' ) ) {
			return;
		}

		$params				=	$row->getParams();
		$forumId			=	$params->get( 'forum_id', null );

		if ( $forumId ) {
			if ( method_exists( $row, 'getCategory' ) ) {
				$authorized	=	cbgjClass::getAuthorization( $row->getCategory(), $row, $user );
			} else {
				$authorized	=	cbgjClass::getAuthorization( $row, null, $user );
			}

			$forumShow		=	(int) cbgjClass::getCleanParam( ( $plugin->params->get( 'forum_show_config', 1 ) || cbgjClass::hasAccess( 'usr_mod', $authorized ) ), 'forum_show', $params->get( 'forum_show', $plugin->params->get( 'forum_show', 1 ) ) );
			$category		=	KunenaForumCategoryHelper::get( (int) $forumId );

			if ( $category->name ) {
				$category->set( 'published', (int) ( ! $forumShow ? 0 : $row->get( 'published' ) ) );
				$category->save();
			}
		}
	}
	/**
	 * save user
	 *
	 * @param int $id
	 * @param string $task
	 * @param moscomprofilerUser $user
	 * @param object $plugin
	 */
	private function saveUserEdit( $id, $task, $user, $plugin ) {
		$row					=	cbgjData::getUsers( null, array( 'id', '=', (int) $id ), null, null, false );
		$group					=	$row->getGroup();
		$userIdArray			=	explode( ',', cbgjClass::getCleanParam( true, 'user_id', $row->get( 'user_id', $user->id ) ) );

		if ( ! empty( $userIdArray ) ) {
			foreach ( $userIdArray as $k => $userId ) {
				if ( $k != 0 ) {
					$row->set( 'id', null );
				}

				$row->set( 'user_id', (int) $userId );
				$row->set( 'group', (int) cbgjClass::getCleanParam( true, 'group', $row->get( 'group' ) ) );
				$row->set( 'date', $row->get( 'date', cbgjClass::getUTCDate() ) );
				$row->set( 'status', (int) cbgjClass::getCleanParam( true, 'status', $row->get( 'status', 1 ) ) );

				if ( ! $row->get( 'user_id' ) ) {
					$row->set( '_error', CBTxt::T( 'User not specified!' ) );
				} elseif ( ! $row->get( 'group' ) ) {
					$row->set( '_error', CBTxt::T( 'Group not specified!' ) );
				} elseif ( ! $row->get( 'id' ) ) {
					$exists		=	cbgjData::getUsers( null, array( array( 'group', '=', (int) $group->get( 'id' ) ), array( 'user_id', '=', (int) $row->get( 'user_id' ) ) ), null, null, false );

					if ( $exists->get( 'id' ) ) {
						$row->set( '_error', CBTxt::T( 'User already belongs to specified group!' ) );
					}
				}

				if ( $row->getError() || ( ! $row->store() ) ) {
					$this->showUserEdit( $row->get( 'id' ), $user, $plugin, CBTxt::P( 'User failed to save! Error: [error]', array( '[error]' => $row->getError() ) ) ); return;
				}

				if ( $row->get( 'status' ) == 4 ) {
					$group->storeOwner( $row->get( 'user_id' ) );
				}

				$row->acceptInvites();
			}

			if ( $task == 'apply' ) {
				cbgjClass::getPluginURL( array( 'users', 'edit', (int) $row->get( 'id' ) ), CBTxt::T( 'User saved successfully!' ), false, true );
			} else {
				cbgjClass::getPluginURL( array( 'users' ), CBTxt::T( 'User saved successfully!' ), false, true );
			}
		}

		$this->showUserEdit( $row->get( 'id' ), $user, $plugin, CBTxt::T( 'User failed to save! Error: User not specified!' ) ); return;
	}