+// Determines database column name from given subject and locked
+function determinePointsColumnFromSubjectLocked ($subject, $locked) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',locked=' . intval($locked) . ' - ENTERED!');
+ // Default is 'normal' points
+ $pointsColumn = 'points';
+
+ // Which points, locked or normal?
+ if ($locked === TRUE) {
+ $pointsColumn = 'locked_points';
+ } // END - if
+
+ // Prepare array for filter
+ $filterData = array(
+ 'subject' => $subject,
+ 'locked' => $locked,
+ 'column' => $pointsColumn
+ );
+
+ // Run the filter
+ $filterData = runFilterChain('determine_points_column_name', $filterData);
+
+ // Extract column name from array
+ $pointsColumn = $filterData['column'];
+
+ // Return it
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',locked=' . intval($locked) . ',pointsColumn=' . $pointsColumn . ' - EXIT!');
+ return $pointsColumn;
+}
+
+// Converts a boolean variable into 'Y' for true and 'N' for false
+function convertBooleanToYesNo ($boolean) {
+ // Default is 'N'
+ $converted = 'N';
+ if ($boolean === TRUE) {
+ // Set 'Y'
+ $converted = 'Y';
+ } // END - if
+
+ // Return it
+ return $converted;
+}
+
+// "Translates" 'true' to true and 'false' to false
+function convertStringToBoolean ($str) {
+ // Debug message (to measure how often this function is called)
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'str=' . $str);
+
+ // Is there cache?
+ if (!isset($GLOBALS[__FUNCTION__][$str])) {
+ // Trim it lower-case for validation
+ $strTrimmed = trim(strtolower($str));
+
+ // Is it valid?
+ if (!in_array($strTrimmed, array('true', 'false'))) {
+ // Not valid!
+ reportBug(__FUNCTION__, __LINE__, 'str=' . $str . '(' . $strTrimmed . ') is not true/false');
+ } // END - if
+
+ // Determine it
+ $GLOBALS[__FUNCTION__][$str] = (($strTrimmed == 'true') ? true : false);
+ } // END - if
+
+ // Return cache
+ return $GLOBALS[__FUNCTION__][$str];
+}
+
+/**
+ * "Makes" a variable in given string parseable, this function will throw an
+ * error if the first character is not a dollar sign.
+ *
+ * @param $varString String which contains a variable
+ * @return $return String with added single quotes for better parsing
+ */
+function makeParseableVariable ($varString) {
+ // The first character must be a dollar sign
+ if (substr($varString, 0, 1) != '$') {
+ // Please report this
+ reportBug(__FUNCTION__, __LINE__, 'varString=' . $varString . ' - No dollar sign detected, will not parse it.');
+ } // END - if
+
+ // Is there cache?
+ if (!isset($GLOBALS[__FUNCTION__][$varString])) {
+ // Snap them in, if [,] are there
+ $GLOBALS[__FUNCTION__][$varString] = str_replace(array('[', ']'), array("['", "']"), $varString);
+ } // END - if
+
+ // Return cache
+ return $GLOBALS[__FUNCTION__][$varString];
+}
+
+// "Getter" for random TAN
+function getRandomTan () {
+ // Generate one
+ return mt_rand(0, 99999);
+}
+
+// Removes any : from subject
+function removeDoubleDotFromSubject ($subject) {
+ // Remove it
+ $subjectArray = explode(':', $subject);
+ $subject = $subjectArray[0];
+ unset($subjectArray);
+
+ // Return it
+ return $subject;
+}
+
+// Adds a given entry to the database
+function memberAddEntries ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $timeColumns = array(), $columnIndex = NULL) {
+ // Is it a member?
+ if (!isMember()) {
+ // Then abort here
+ return FALSE;
+ } // END - if
+
+ // Set POST data generic userid
+ setPostRequestElement('userid', getMemberId());
+
+ // Call inner function
+ doGenericAddEntries($tableName, $columns, $filterFunctions, $extraValues, $timeColumns, $columnIndex);
+
+ // Entry has been added?
+ if ((!SQL_HASZEROAFFECTED()) && ($GLOBALS['__XML_PARSE_RESULT'] === TRUE)) {
+ // Display success message
+ displayMessage('{--MEMBER_ENTRY_ADDED--}');
+ } else {
+ // Display failed message
+ displayMessage('{--MEMBER_ENTRY_NOT_ADDED--}');
+ }
+}
+
+// Edit rows by given id numbers
+function memberEditEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $timeColumns = array(), $editNow = array(FALSE), $idColumn = array('id'), $userIdColumn = array('userid'), $rawUserId = array('userid'), $cacheFiles = array()) {
+ // $tableName must be an array
+ if ((!is_array($tableName)) || (count($tableName) != 1)) {
+ // No tableName specified
+ reportBug(__FUNCTION__, __LINE__, 'tableName is not given. Please fix your XML,tableName[]=' . gettype($tableName) . '!=array: userIdColumn=' . $userIdColumn);
+ } elseif (!is_array($idColumn)) {
+ // $idColumn is no array
+ reportBug(__FUNCTION__, __LINE__, 'idColumn[]=' . gettype($idColumn) . '!=array: userIdColumn=' . $userIdColumn);
+ } elseif (!is_array($userIdColumn)) {
+ // $userIdColumn is no array
+ reportBug(__FUNCTION__, __LINE__, 'userIdColumn[]=' . gettype($userIdColumn) . '!=array: userIdColumn=' . $userIdColumn);
+ } elseif (!is_array($editNow)) {
+ // $editNow is no array
+ reportBug(__FUNCTION__, __LINE__, 'editNow[]=' . gettype($editNow) . '!=array: userIdColumn=' . $userIdColumn);
+ } // END - if
+
+ // Shall we change here or list for editing?
+ if ($editNow[0] === TRUE) {
+ // Add generic userid field
+ setPostRequestElement('userid', getMemberId());
+
+ // Call generic change method
+ $affected = doGenericEditEntriesConfirm($tableName, $columns, $filterFunctions, $extraValues, $timeColumns, $editNow, $idColumn, $userIdColumn, $rawUserId, $cacheFiles, 'mem_edit');
+
+ // Was this fine?
+ if ($affected == countPostSelection($idColumn[0])) {
+ // All deleted
+ displayMessage('{--MEMBER_ALL_ENTRIES_EDITED--}');
+ } else {
+ // Some are still there :(
+ displayMessage(sprintf(getMessage('MEMBER_SOME_ENTRIES_NOT_EDITED'), $affected, countPostSelection($idColumn[0])));
+ }
+ } else {
+ // List for editing
+ memberListBuilder('edit', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
+ }
+}
+
+// Delete rows by given id numbers
+function memberDeleteEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $deleteNow = array(FALSE), $idColumn = array('id'), $userIdColumn = array('userid'), $rawUserId = array('userid'), $cacheFiles = array()) {
+ // Do this only for members
+ assert(isMember());
+
+ // $tableName must be an array
+ if ((!is_array($tableName)) || (count($tableName) != 1)) {
+ // No tableName specified
+ reportBug(__FUNCTION__, __LINE__, 'tableName is not given. Please fix your XML,tableName[]=' . gettype($tableName) . '!=array: userIdColumn=' . $userIdColumn);
+ } elseif (!is_array($idColumn)) {
+ // $idColumn is no array
+ reportBug(__FUNCTION__, __LINE__, 'idColumn[]=' . gettype($idColumn) . '!=array: userIdColumn=' . $userIdColumn);
+ } elseif (!is_array($userIdColumn)) {
+ // $userIdColumn is no array
+ reportBug(__FUNCTION__, __LINE__, 'userIdColumn[]=' . gettype($userIdColumn) . '!=array: userIdColumn=' . $userIdColumn);
+ } elseif (!is_array($deleteNow)) {
+ // $deleteNow is no array
+ reportBug(__FUNCTION__, __LINE__, 'deleteNow[]=' . gettype($deleteNow) . '!=array: userIdColumn=' . $userIdColumn);
+ } // END - if
+
+ // Shall we delete here or list for deletion?
+ if ($deleteNow[0] === TRUE) {
+ // Add generic userid field
+ setPostRequestElement('userid', getMemberId());
+
+ // Call generic function
+ $affected = doGenericDeleteEntriesConfirm($tableName, $columns, $filterFunctions, $extraValues, $deleteNow, $idColumn, $userIdColumn, $rawUserId, $cacheFiles, 'mem_delete');
+
+ // Was this fine?
+ if ($affected == countPostSelection($idColumn[0])) {
+ // All deleted
+ displayMessage('{--MEMBER_ALL_ENTRIES_REMOVED--}');
+ } else {
+ // Some are still there :(
+ displayMessage(sprintf(getMessage('MEMBER_SOME_ENTRIES_NOT_DELETED'), SQL_AFFECTEDROWS(), countPostSelection($idColumn[0])));
+ }
+ } else {
+ // List for deletion confirmation
+ memberListBuilder('delete', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
+ }
+}
+
+// Build a special template list
+function memberListBuilder ($listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId = array('userid')) {
+ // Do this only for logged in member
+ assert(isMember());
+
+ // Call inner (general) function
+ doGenericListBuilder('member', $listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId);
+}
+
+// Checks whether given address is IPv4
+function isIp4AddressValid ($address) {
+ // Is there cache?
+ if (!isset($GLOBALS[__FUNCTION__][$address])) {
+ // Determine it ...
+ $GLOBALS[__FUNCTION__][$address] = preg_match('/((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9]))/', $address);
+ } // END - if
+
+ // Return cache
+ return $GLOBALS[__FUNCTION__][$address];
+}
+
+// ----------------------------------------------------------------------------
+// "Translatation" functions for points_data table
+// ----------------------------------------------------------------------------
+
+// Translates generically some data into a target string
+function translateGeneric ($messagePrefix, $data) {
+ // Is the method null or empty?
+ if (is_null($data)) {
+ // Is NULL
+ $data = 'NULL';
+ } elseif (empty($data)) {
+ // Is empty (string)
+ $data = 'EMPTY';
+ } // END - if
+
+ // Default column name is unknown
+ $return = '{%message,' . $messagePrefix . '_UNKNOWN=' . strtoupper($data) . '%}';
+
+ // Construct message id
+ $messageId = $messagePrefix . '_' . strtoupper($data);
+
+ // Is it there?
+ if (isMessageIdValid($messageId)) {
+ // Then use it as message string
+ $return = '{--' . $messageId . '--}';
+ } // END - if
+
+ // Return the column name
+ return $return;
+}
+
+// Translates points subject to human-readable
+function translatePointsSubject ($subject) {
+ // Remove any :x
+ $subject = removeDoubleDotFromSubject($subject);
+
+ // Return it
+ return translateGeneric('POINTS_SUBJECT', $subject);
+}
+
+// "Translates" the given points account type
+function translatePointsAccountType ($accountType) {
+ // Return it
+ return translateGeneric('POINTS_ACCOUNT_TYPE', $accountType);
+}
+
+// "Translates" the given points "locked mode"
+function translatePointsLockedMode ($lockedMode) {
+ // Return it
+ return translateGeneric('POINTS_LOCKED_MODE', $lockedMode);
+}
+
+// "Translates" the given points payment method
+function translatePointsPaymentMethod ($paymentMethod) {
+ // Return it
+ return translateGeneric('POINTS_PAYMENT_METHOD', $paymentMethod);
+}
+
+// "Translates" the given points account provider
+function translatePointsAccountProvider ($accountProvider) {
+ // Return it
+ return translateGeneric('POINTS_ACCOUNT_PROVIDER', $accountProvider);
+}
+
+// "Translates" the given points notify recipient
+function translatePointsNotifyRecipient ($notifyRecipient) {
+ // Return it
+ return translateGeneric('POINTS_NOTIFY_RECIPIENT', $notifyRecipient);
+}
+
+// Translates task type to a human-readable version
+function translateTaskType ($taskType) {
+ // Return it
+ return translateGeneric('ADMIN_TASK_TYPE', $taskType);
+}
+