static function getDocumentID($args) { $button_id = $args["button_id"]; if (!is_null(self::$current_doc_id) && self::$current_button_id == $button_id) { return self::$current_doc_id; } if (self::$doNext == false) { foreach (self::$documentArray as $index => $ids) { foreach ($ids as $doc_button_id => $doc_vars) { if ($doc_button_id == $button_id) { if (!$doc_vars["done"]) { return $doc_vars["document_id"]; } } } } } // if not found in documentarray make a new one $loaded = self::$loadedButtons; end($loaded); $i = 0; foreach ($loaded as $btn_id) { if ($btn_id == $button_id) { $i++; } } $i--; // minus the current added button.. //$index = key($loaded); // find last index if ($i == 0) { $document_id = $button_id; } else { $document_id = $button_id . "_" . $i; } self::$doNext = false; self::$current_doc_id = $document_id; self::$current_button_id = $button_id; return $document_id; }