+// 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(), $content = 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, $rawUserId, $content);
+ }
+}
+
+// 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(), $content = 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, $rawUSerId, $content);
+ }
+}
+
+// Build a special template list
+// @TODO cacheFiles is not yet supported
+function memberListBuilder ($listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId = array('userid'), $content = array()) {
+ // Do this only for logged in member
+ assert(isMember());
+
+ // Call inner (general) function
+ doGenericListBuilder('member', $listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId, $content);
+}
+
+// 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];
+}
+
+// Returns the string if not empty or FALSE if empty
+function validateIsEmpty ($str) {
+ // Trim it
+ $trimmed = trim($str);
+
+ // Is the string empty?
+ if (empty($trimmed)) {
+ // Then set FALSE
+ $str = FALSE;
+ } // END - if
+
+ // Return it
+ return $str;
+}
+
+// ----------------------------------------------------------------------------
+// "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" given points account type
+function translatePointsAccountType ($accountType) {
+ // Return it
+ return translateGeneric('POINTS_ACCOUNT_TYPE', $accountType);
+}
+
+// "Translates" given points "locked mode"
+function translatePointsLockedMode ($lockedMode) {
+ // Return it
+ return translateGeneric('POINTS_LOCKED_MODE', $lockedMode);
+}
+
+// "Translates" given points payment method
+function translatePointsPaymentMethod ($paymentMethod) {
+ // Return it
+ return translateGeneric('POINTS_PAYMENT_METHOD', $paymentMethod);
+}
+
+// "Translates" given points account provider
+function translatePointsAccountProvider ($accountProvider) {
+ // Return it
+ return translateGeneric('POINTS_ACCOUNT_PROVIDER', $accountProvider);
+}
+
+// "Translates" given points notify recipient
+function translatePointsNotifyRecipient ($notifyRecipient) {
+ // Return it
+ return translateGeneric('POINTS_NOTIFY_RECIPIENT', $notifyRecipient);
+}
+
+// "Translates" given mode to a human-readable version
+function translatePointsMode ($pointsMode) {
+ // Return it
+ return translateGeneric('POINTS_MODE', $pointsMode);
+}
+
+// "Translates" task type to a human-readable version
+function translateTaskType ($taskType) {
+ // Return it
+ return translateGeneric('ADMIN_TASK_TYPE', $taskType);