+ return SURFBAR_REGISTER_URL($url, getUserId(), 'PENDING', 'reg', array('limit' => $limit));
+}
+
+// Create list of actions depending on status for the user
+function SURFBAR_MEMBER_ACTIONS ($urlId, $status) {
+ // Load all actions in an array for given status
+ $actionArray = SURFBAR_getModeAction_ARRAY($status);
+
+ // Init HTML code
+ $OUT = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" width=\"100%\">
+<tr>\n";
+
+ // Calculate width
+ $width = round(100 / count($actionArray));
+
+ // "Walk" through all actions and create forms
+ foreach ($actionArray as $actionId => $action) {
+ // Add form for this action
+ $OUT .= LOAD_TEMPLATE('member_surfbar_list_form', true, array(
+ 'width' => $width,
+ 'id' => bigintval($urlId),
+ 'action' => strtolower($action),
+ 'title' => '{--MEMBER_SURFBAR_ACTION_' . strtoupper($action) . '_TITLE--}',
+ 'submit' => '{--MEMBER_SURFBAR_ACTION_' . strtoupper($action) . '_SUBMIT--}',
+ ));
+ } // END - foreach
+
+ // Close table
+ $OUT .= "</tr>
+</table>\n";
+
+ // Return code
+ return $OUT;
+}
+
+// Do the member form request
+function SURFBAR_MEMBER_DO_FORM ($formData, $URLs) {
+ // By default no action is performed
+ $performed = false;
+
+ // Is this a member?
+ if (!IS_MEMBER()) {
+ // No member!
+ return false;
+ } elseif ((!isset($formData['id'])) || (!isset($formData['action']))) {
+ // Important form elements are missing!
+ return false;
+ } elseif (!isset($URLs[$formData['id']])) {
+ // ID not found in cache
+ return false;
+ } elseif (!SURFBAR_VALIDATE_MEMBER_ACTION_STATUS($formData['action'], $URLs[$formData['id']]['status'])) {
+ // Action not allowed for current URL status
+ return false;
+ }
+
+ // Secure action
+ $action = SQL_ESCAPE(htmlentities(strip_tags($formData['action']), ENT_QUOTES));
+
+ // Has it changed?
+ if ($action != $formData['action']) {
+ // Invalid data in action found
+ return false;
+ } // END - if
+
+ // Create the function name for selected action
+ $functionName = sprintf("SURFBAR_MEMBER_%s_ACTION", strtoupper($action));
+
+ // Is the function there?
+ if (function_exists($functionName)) {
+ // Add new status
+ $URLs[$formData['id']]['new_status'] = SURFBAR_GET_NEW_STATUS('new_status');
+
+ // Extract URL data for call-back
+ $urlData = array(merge_array($URLs[$formData['id']], array($action => $formData)));
+
+ // Action found so execute it
+ $performed = call_user_func_array($functionName, $urlData);
+ } else {
+ // Log invalid request
+ DEBUG_LOG(__FUNCTION__, __LINE__, " action={$formData['action']},id={$formData['id']},function={$functionName}");
+ addFatalMessage(__FUNCTION__, __LINE__, "Invalid member action! action=%s,id=%s,function=%s", array($formData['action'], $formData['id'], $functionName));
+ }
+
+ // Return status
+ return $performed;
+}
+
+// Validate if the requested action can be performed on current URL status
+function SURFBAR_VALIDATE_MEMBER_ACTION_STATUS ($action, $status) {
+ // Search for the requested action/status combination in database
+ $result = SQL_QUERY_ESC("SELECT new_status FROM `{!_MYSQL_PREFIX!}_surfbar_actions` WHERE `action`='%s' AND `status`='%s' LIMIT 1",
+ array($action, $status), __FUNCTION__, __LINE__);
+
+ // Is the entry there?
+ $isValid = (SQL_NUMROWS($result) == 1);
+
+ // Fetch the new status if found
+ if ($isValid) {
+ // Load new status
+ list($GLOBALS['surfbar_cache']['new_status']) = SQL_FETCHROW($result);
+ } // END - if
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Return status
+ return $isValid;
+}
+
+//
+// -----------------------------------------------------------------------------
+// Member actions
+// -----------------------------------------------------------------------------
+//
+// Retreat a booked URL
+function SURFBAR_MEMBER_RETREAT_ACTION ($urlData) {
+ // Create the data array for next function call
+ $data = array(
+ $urlData['id'] => $urlData
+ );
+
+ // Simply change the status here
+ return SURFBAR_CHANGE_STATUS ($urlData['id'], $urlData['status'], $urlData['new_status'], $data);
+}
+
+// Book an URL now (from migration)
+function SURFBAR_MEMBER_BOOKNOW_ACTION ($urlData) {
+ // Create the data array for next function call
+ $data = array(
+ $urlData['id'] => $urlData
+ );
+
+ // Simply change the status here
+ return SURFBAR_CHANGE_STATUS ($urlData['id'], $urlData['status'], $urlData['new_status'], $data);
+}
+
+// Show edit form or do the changes
+function SURFBAR_MEMBER_EDIT_ACTION ($urlData) {
+ // Is the "execute" flag there?
+ if (isset($urlData['edit']['execute'])) {
+ // Execute the changes
+ return SURFBAR_MEMBER_EXECUTE_ACTION('edit', $urlData);
+ } // END - if
+
+ // Display form
+ return SURFBAR_MEMBER_DISPLAY_ACTION_FORM('edit', $urlData);
+}
+
+// Show delete form or do the changes
+function SURFBAR_MEMBER_DELETE_ACTION ($urlData) {
+ // Is the "execute" flag there?
+ if (isset($urlData['delete']['execute'])) {
+ // Execute the changes
+ return SURFBAR_MEMBER_EXECUTE_ACTION('delete', $urlData);
+ } // END - if
+
+ // Display form
+ return SURFBAR_MEMBER_DISPLAY_ACTION_FORM('delete', $urlData);
+}
+
+// Pause active banner
+function SURFBAR_MEMBER_PAUSE_ACTION ($urlData) {
+ return SURFBAR_CHANGE_STATUS($urlData['id'], $urlData['status'], $urlData['new_status'], array($urlData['id'] => $urlData));
+}
+
+// Unpause stopped banner
+function SURFBAR_MEMBER_UNPAUSE_ACTION ($urlData) {
+ // Fix missing entry for template
+ $urlData['edit'] = $urlData['unpause'];
+ $urlData['edit']['url'] = $urlData['url'];
+ $urlData['edit']['limit'] = $urlData['views_max'];
+
+ // Return status change
+ return SURFBAR_CHANGE_STATUS($urlData['id'], $urlData['status'], $urlData['new_status'], array($urlData['id'] => $urlData));
+}
+
+// Resubmit locked URL
+function SURFBAR_MEMBER_RESUBMIT_ACTION ($urlData) {
+ return SURFBAR_CHANGE_STATUS($urlData['id'], $urlData['status'], $urlData['new_status'], array($urlData['id'] => $urlData));